[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
17.1.1 Thread API
Bigloo uses a set of primitive functions and methods to create, run and handle thread. For the sake of standardization the name and semantic of SRFI-18 has been used. This section presents only the mandatory functions to program with threads in Bigloo.
The most important difference with SRFI-18, is the missing of the
function make-thread
, which is not available for all libraries,
as it can be hard to predict the type of thread which will be created
if several thread libraries are used simultaneously. As threads are
regular Bigloo objects, they can be created using the
instantiate
syntax. See the Threads and Posix Threads
specific sections for more details about thread creation and
examples.
The examples given in this section use a generic
syntax with instantiate::thread
, to run the examples, you will
have to put them in a function in a module (see Section Modules,
and import one of the libraries using library
module
declaration.
- SRFI-18 function: thread-specific thread
- SRFI-18 function: thread-specific-set! thread obj
Returns and sets value in the specific field of the thread. If no value has been set,
thread-specific
returns an unspecified value.(let ((t (instantiate::thread (body (lambda () (print (thread-specific (current-thread)))))))) (thread-specific-set! t 'foo) (thread-start! t)) -| foo
- Bigloo function: thread-cleanup thread
- Bigloo function: thread-cleanup-set! thread fun
Associates a cleanup function to a thread. The cleanup function is called with the thread itself. The cleanup function is executed in a context where
current-thread
is the thread owning the cleanup function.(let ((t (instantiate::thread (body (lambda () 'done) 'foo)))) (thread-cleanup-set! t (lambda (v) (print (thread-name (current-thread)) ", exit value: " v))) (thread-start! t)) -| foo, exit value: done
- Bigloo function: thread-parameter ident
- Bigloo function: thread-parameter-set! ident value
Returns the value of the parameter ident in the current thread. If no value is bound to this parameter,
#f
is returned.A thread parameter is implemented by a chunk of memory specific to each thread. All threads are created with an empty set of parameters.
The next functions have different behaviors depending in the library used, more details will be given in the specific sections below.
- SRFI-18 function: thread-start! thread [args]
- Bigloo function: thread-start-joinable! thread
- SRFI-18 function: thread-join! thread [timeout]
- SRFI-18 function: thread-terminate! thread
- SRFI-18 function: thread-yield!
- SRFI-18 function: thread-sleep! timeout
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 31, 2014 using texi2html 5.0.