Patch title: Release 85 bulk changes
Abstract:
File: /pliant/language/schedule/threads_engine.pli
Key:
    Removed line
    Added line
   
# Copyright  Hubert Tonneau  hubert.tonneau@pliant.cx
#
# This program is free software; you can redistribute it and
# modify it under the terms of the GNU General Public Licens
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be us
# but WITHOUT ANY WARRANTY; without even the implied warrant
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See 
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public 
# version 2 along with this program; if not, write to the Fr
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 


    function run_thread action -> success
      arg DelayedAction action ; arg CBool success
      if thread_trace
        console "run "+action:function:position+"[lf]"
      recycling_sem request
      if exists:recycling_first
        var Pointer:ThreadHeader h :> recycling_first
        recycling_first :> h next
        recycling_sem release
        h action := action
        restart_thread h
        return true
      recycling_sem release
      terminate_zombies
      atomic_add current_running_threads 1
      maximum_running_threads := max maximum_running_threads
      var Pointer:ThreadHeader h :> allocate_stack
      if not exists:h
        atomic_add current_running_threads -1
        return false
      h variables_context := current_thread_header variables
      DelayedAction build_instance (addressof h:action)
      ErrorRecord build_instance (addressof h:bottom_error)
      h action := action
      h setup      
      var Int pid := os_clone 8F00h (addressof:h translate B
      if pid=0
        h :> current_thread_header
        h pid := os_getpid
        os_sigsetmask 2^(pliant_suspend_signal-1)
        thread_insert_header h
        execute1 h:action:parameter h:action:function
        error_report
# Copyright  Hubert Tonneau  hubert.tonneau@pliant.cx
#
# This program is free software; you can redistribute it and
# modify it under the terms of the GNU General Public Licens
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be us
# but WITHOUT ANY WARRANTY; without even the implied warrant
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See 
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public 
# version 2 along with this program; if not, write to the Fr
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 


    function run_thread action -> success
      arg DelayedAction action ; arg CBool success
      if thread_trace
        console "run "+action:function:position+"[lf]"
      recycling_sem request
      if exists:recycling_first
        var Pointer:ThreadHeader h :> recycling_first
        recycling_first :> h next
        recycling_sem release
        h action := action
        restart_thread h
        return true
      recycling_sem release
      terminate_zombies
      atomic_add current_running_threads 1
      maximum_running_threads := max maximum_running_threads
      var Pointer:ThreadHeader h :> allocate_stack
      if not exists:h
        atomic_add current_running_threads -1
        return false
      h variables_context := current_thread_header variables
      DelayedAction build_instance (addressof h:action)
      ErrorRecord build_instance (addressof h:bottom_error)
      h action := action
      h setup      
      var Int pid := os_clone 8F00h (addressof:h translate B
      if pid=0
        h :> current_thread_header
        h pid := os_getpid
        os_sigsetmask 2^(pliant_suspend_signal-1)
        thread_insert_header h
        execute1 h:action:parameter h:action:function
        error_report
        while pliant_execution_phase<=execution_phase_run
        while pliant_execution_phase<=execution_phase_run and (exists h:action:function)
          DelayedAction destroy_instance (addressof h:action
          DelayedAction build_instance (addressof h:action)
          ActionRecord build_instance addressof:(var ActionR
          action_push_record (var ActionRecord ar) "recyclin
          recycling_sem request
          h next :> recycling_first
          recycling_first :> h
          recycling_sem release
          stop_current_thread
          action_pull_record ar
          ActionRecord destroy_instance addressof:ar
          DelayedAction destroy_instance (addressof h:action
          DelayedAction build_instance (addressof h:action)
          ActionRecord build_instance addressof:(var ActionR
          action_push_record (var ActionRecord ar) "recyclin
          recycling_sem request
          h next :> recycling_first
          recycling_first :> h
          recycling_sem release
          stop_current_thread
          action_pull_record ar
          ActionRecord destroy_instance addressof:ar
          execute1 h:action:parameter h:action:function
          if (exists h:action:function)
            execute1 h:action:parameter h:action:function
          error_report
        thread_remove_header h
        ErrorRecord destroy_instance (addressof h:bottom_err
        record_zombie h
        atomic_add current_running_threads -1
        os_exit 0
      eif pid=(-1)
        DelayedAction destroy_instance (addressof h:action)
        free_stack h
        atomic_add current_running_threads -1
        return false
      else
        return true

          error_report
        thread_remove_header h
        ErrorRecord destroy_instance (addressof h:bottom_err
        record_zombie h
        atomic_add current_running_threads -1
        os_exit 0
      eif pid=(-1)
        DelayedAction destroy_instance (addressof h:action)
        free_stack h
        atomic_add current_running_threads -1
        return false
      else
        return true

  function threads_shrink
    recycling_sem request
    while exists:recycling_first
      var Pointer:ThreadHeader h :> recycling_first
      recycling_first :> h next
      restart_thread h
    recycling_sem release
  
eif os_api="posix"


eif os_api="posix"


  function threads_shrink
     void

eif os_api="win32"


eif os_api="win32"


  function threads_shrink
     void

eif os_api="os2"


eif os_api="os2"


  function threads_shrink
     void

if os_api="linux" or os_api="posix" or os_api="win32" or os_
  if addressof:current_thread_header<>addressof:first_thread
    error error_id_os "Threads interface seems to be buggy u


if os_api="linux" or os_api="posix" or os_api="win32" or os_
  if addressof:current_thread_header<>addressof:first_thread
    error error_id_os "Threads interface seems to be buggy u


export run_thread current_thread_header
export run_thread threads_shrink current_thread_header
export current_running_threads maximum_running_threads



export current_running_threads maximum_running_threads