« Home » « Learn » « Download » « Github »

logo

Cello High Level C

Examples

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 */

Thread


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.

Derives

Implements

  • Assignassign
  • C_Intc_int
  • Callcall
  • Cmpcmp eq neq gt lt ge le
  • Currentcurrent
  • Docname brief description definition
  • Getget set mem rem key_type val_type
  • Hashhash hash_data
  • Markmark
  • Newnew del construct destruct
  • Startwith start stop join running

Back