The library provides thread related procedures. The procedures provided this library is based on SRFI-18 Multithreading support and Sagittarius specific procedures.
[SRFI-18] Returns #t if given obj is a thread, otherwise #f.
[SRFI-18] Returns the current thread.
[SRFI-18] Returns a new thread. The created thread is not executed.
To run it, users must explicitly call the thread-start!
procedure.
The optional argument name gives the thread a name. The name can be
retrieved calling thread-name
procedure. If the argument is not given,
then the make-thread
procedures creates an unique name.
[SRFI-18] Returns the name of thread.
Returns the current state of thread.
[SRFI-18] Returns the content of the thread's specific slot.
[SRFI-18] Stores obj into the thread's specific slot and returns unspecified value.
[SRFI-18] Executes the given thread and returns thread
[SRFI-18] The current thread exits the running state if its quantum had expired.
[SRFI-18] The current thread waits until the timeout is reached.
timeout must be either a time object or an exact integer. The first case, it represents absolute time of the future. The latter case represents second from current time.
[SRFI-18] Causes an abnormal termination of the thread. If
the thread is not already terminated, all mutexes owned by the
thread become unlocked/abandoned and a "terminated thread exception"
object is stored in the thread's end-exception field. If _thread_is the current thread, thread-terminate!
does not return. Otherwise
thread-terminate!
returns an unspecified value; the termination of
the thread will occur before thread-terminate!
returns.
[SRFI-18] The current thread waits until the thread terminates
(normal or not) or until the timeout is reached if timeout is
specified. If the timeout is reached, thread-join!
returns
timeout-val if it is supplied, otherwise a "join timeout exception"
is raised. If the thread terminated normally, the content of the
end-result field is returned, otherwise the content of the end-exception
field is raised.
Suspends execution of the thread. Users can resume the _thread_by calling thread-resume!
.
Resumes execution of the thread.
If the caller thread is not the one stopped the target thread, then the procedure raises an error.
Interrupts blocking system call.
This procedure causes EINTR
and cancels blocking system call such
as select (2)
. Currently the only relevant procedure for this is
socket-select
related procedures. See
socket library - Low level APIs.
Currently the procedure uses SIGALRM
on POSIX environment. This
might be changed in future, so do not depend on the signal to interrupt
the call from outside of Sagittarius process.
On Windows, the procedure uses combination of WSAEventSelect
and
WaitForMultipleObjects
. So there is no way to interrupt from
outside of Sagittarius process.
[SRFI-18] Returns #t if given obj is a mutex, otherwise #f.
[SRFI-18] Returns a new mutex.
The optional argument name gives the mutex a name. If it's not specified, then the procedure makes an unique name.
[SRFI-18] Returns the name of given mutex.
[SRFI-18] Returns the content of specific slot of given mutex.
[SRFI-18] Stores the obj to given mutex's specific slot.
[SRFI-18] Returns the state of given mutex.
[SRFI-18] Locks the given mutex. If the mutex is currently locked, the current thread waits the mutex is unlocked or until the timeout is reached. If timeout is reached, the procedure returns #f.
[SRFI-18] Unlocks the given mutex. If condition variable _cv_is specified, the current thread is blocked and added to the cv before
unlocking mutex, the thread can unblock at any time but no later than
when an appropriate call to condition-variable-signal!
or
condition-variable-broadcast!
is performed, and no later than the
timeout, if it's given.
[SRFI-18] Returns #t if given obj is a condition variable, otherwise #f.
[SRFI-18] Returns a new condition variable.
The optional argument name gives the condition variable a name. If it's not specified, then the procedure makes an unique name.
[SRFI-18] Returns the name of given cv.
[SRFI-18] Returns the content of specific slot of given cv.
[SRFI-18] Stores the obj to given cv's specific slot.
[SRFI-18] If there are thread blocked on cv, the scheduler selects a thread and unblocks it.
[SRFI-18] Unblocks all the threads blocked on the cv.
Returns #t if given obj is a semaphore, otherwise #f.
Creates a new semaphore with initial count initial__name must be either #f or string which represents semaphore name. If the value is #f, then the returning semaphore is memory based semaphore.
initial must be non negative integer.
If there is already the semaphore has the same name, then this procedure returns that semaphore instead of creating new one.
Opens semaphore which has name.
If there is no such semaphore, then the procedure raises
&i/o-file-does-not-exist
.
Returns the name of given semaphore.
Locks the semaphore. If the current count of _semaphore_is 0, then the procedure waits.
The optional argument timeout is specified, which it must be #f, integer or time object, then the procedure only waits the given timeout amount. #f means inifinite.
Unlock the semaphore. This procedure increase the count of semaphore.
Closes the semaphore.
Removes the semaphore.
NOTE: the semaphore-close!
and semaphore-destroy!
behaves the
same on Windows.