{"size": 1344, "ext": "scrbl", "max_stars_repo_path": "pkgs/racket-doc/scribblings/inside/cs-thread.scrbl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pkgs/racket-doc/scribblings/inside/cs-thread.scrbl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2020-07-31T19:59:17.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-01T08:43:47.000Z", "max_forks_repo_path": "pkgs/racket-doc/scribblings/inside/cs-thread.scrbl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 38.4, "max_line_length": 70, "alphanum_fraction": 0.7976190476}
#lang scribble/doc
@(require "utils.rkt")

@title[#:tag "cs-thread"]{Managing OS-Level Threads}

Chez Scheme functionality can only be accessed from OS-level threads
that are known to the Chez Scheme runtime system. Otherwise, there's a
race condition between such an access and a garbage collection that is
triggered by other threads.

A thread not created by Chez Scheme can be made known to the runtime
system by activating it with @cppi{Sactivate_thread}. As long as a
thread is active by not running Chez Scheme code, the thread prevents
garbage collection in all other running threads. Deactivate a thread
using @cppi{Sdeactivate_thread}. When a deactivated thread 

@function[(int Sactivate_thread)]{

Activates the current OS-level thread. An already-activated thread can
be activated again, but each activating must be balanced by a
decativation. The result is @cpp{0} if the thread was previously
activated @cpp{1} otherwise.}

@function[(void Sdeactivate_thread)]{

Deactivates the current OS-level thread---or, at least, balances on
activation, making the thread deactive if there are no remaining
activations to balance with deactivation.}

@function[(int Sdestroy_thread)]{

Releases any Chez Scheme resources associated with the current OS
thread, which must have been previously activated by which must not be
activated still.}
