Usage
var set_value(var args) {
assign(get(args, $I(0)), $I(1));
return NULL;
}
var i = $I(0);
var x = new(Thread, $(Function, set_value));
call(x, i);
join(x);
show(i); /* 1 */
Exclusive Resource
var increment(var args) {
var mut = get(args, $I(0));
var tot = get(args, $I(1));
lock(mut);
assign(tot, $I(c_int(tot)+1));
unlock(mut);
return NULL;
}
var mutex = new(Mutex);
var total = $I(0);
var threads = new(Array, Box,
new(Thread, $(Function, increment)),
new(Thread, $(Function, increment)),
new(Thread, $(Function, increment)));
show(total); /* 0 */
foreach (t in threads) {
call(deref(t), mutex, total);
}
foreach (t in threads) {
join(deref(t));
}
show(total); /* 3 */
Concurrent Execution
The Thread
type provides a basic primitive for concurrent execution. It acts as a basic wrapper around operating system threads, using WinThreads on Windows and pthreads otherwise.
assign
c_int
call
cmp
eq
neq
gt
lt
ge
le
current
name
brief
description
definition
get
set
mem
rem
key_type
val_type
hash
hash_data
mark
new
del
construct
destruct
with
start
stop
join
running