Threads
An Api to create and manage system threads.
'thread thread_create(f : function:1, p : any) Creates a thread that will be running the function f(p)
'thread thread_current() Returns the current thread
void thread_send('thread, msg : any) Send a message into the target thread message queue
any thread_read_message(block : bool)
Reads a message from the message queue. If block is true, the
function only returns when a message is available. If block is
false and no message is available in the queue, the function will
return immediatly null.
'lock lock_create() Creates a lock which is initially locked
void lock_release('lock)
Release a lock. The thread does not need to own the lock to be
able to release it. If a lock is released several times, it can be
acquired as many times
bool lock_wait('lock, timeout : number?)
Waits for a lock to be released and acquire it.
If timeout (in seconds) is not null and expires then
the returned value is false
'tls tls_create()
Creates thread local storage. This is placeholder that can store a value that will
be different depending on the local thread. You must set the tls value to null
before exiting the thread or the memory will never be collected.
any tls_get('tls)
Returns the value set by tls_set for the local thread.
void tls_set('tls, any)
Set the value of the TLS for the local thread.
'mutex mutex_create()
Creates a mutex, which can be used to acquire a temporary lock to access some ressource.
The main difference with a lock is that a mutex must always be released by the owner thread.
void mutex_acquire('mutex)
The current thread acquire the mutex or wait if not available. The same thread can acquire
several times the same mutex but must release it as many times it has been acquired.
bool mutex_try('mutex)
Try to acquire the mutex, returns true if acquire or false if it's already locked by another
thread.
void mutex_release('mutex)
Release a mutex that has been acquired by the current thread. The behavior is undefined if the
current thread does not own the mutex.
'deque deque_create() create a message queue for multithread access
void deque_add('deque, any) add a message at the end of the queue
void deque_push('deque, any) add a message at the head of the queue
any? deque_pop('deque, bool) pop a message from the queue head. Either block until a message is available or return immedialtly with null.