Plange


an alias for the current ExecutionContext

Example

MergeSortedLists := (List<Int> a, List<Int> b) {
	<List<Int> result;
	<Int> q;
	<ExecutionContext> mainRoutine;

	// construct the first coroutine
	a ← ExecutionContext({
		for (i ∈ a) {
			if (i > q) {
				q ← i;
				fiberB.switch(); //symmetric context switch
			}
			result.append(i);
		}
	});

	// second coroutine
	b ← ExecutionContext({
		for (i ∈ b) {
			if (i > q) {
				q ← i;
				fiberA.switch();
			}
			result.append(i);
		}
	});

	if (a.count > 0) {
		//seed the algorithm
		q ← a[0];
		b.switch(context); //asymmetric context switch returns here when done
	};
}
			

Notes

The value of 'context' contains members for inspecting the current scope and its parents. It can be thought of as localized reflection. It can also be used as a re-entry point for cooperative multi-threading. In this capacity, it also increments a call counter, and stores a user object for passing in data during re-entry. See ExecutionContext


copyright © Brent Lewis 2017