orc.runtime
Class Kilim

java.lang.Object
  extended by orc.runtime.Kilim

public class Kilim
extends java.lang.Object

Utility methods for Kilim.

Author:
quark

Nested Class Summary
static class Kilim.PausableCallable<V>
          Pausable computation which returns a value.
static class Kilim.Promise<V>
          Wrap a callable in a lazy, concurrency-safe promise.
 
Field Summary
static java.lang.Object signal
          Kilim mailboxes can't accomodate null values, so this acts as a basic signal or unit value when necessary.
 
Constructor Summary
Kilim()
           
 
Method Summary
static void runPausable(Token caller, Kilim.PausableCallable<? extends java.lang.Object> thunk)
          Utility method to run a pausable computation which generates a value for a token.
static
<V> V
runThreaded(java.util.concurrent.Callable<V> thunk)
          Spawn a thread to compute a value.
static void runThreaded(java.lang.Runnable thunk)
          Spawn a thread asynchronously.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

signal

public static final java.lang.Object signal
Kilim mailboxes can't accomodate null values, so this acts as a basic signal or unit value when necessary.

Constructor Detail

Kilim

public Kilim()
Method Detail

runThreaded

public static <V> V runThreaded(java.util.concurrent.Callable<V> thunk)
                     throws kilim.Pausable,
                            java.lang.Exception
Spawn a thread to compute a value. This is a common idiom in a Kilim computation, when you need to make blocking calls.

FIXME: I ran into about 5 different weird Kilim bugs trying to write this function; the current structure is not ideal but it was the only one which worked.

FIXME: Kilim mailboxes cannot handle null messages so we always have to return some object.

Throws:
kilim.Pausable
java.lang.Exception

runThreaded

public static void runThreaded(java.lang.Runnable thunk)
                        throws kilim.Pausable
Spawn a thread asynchronously. If you want to block until the thread is complete, use runThreaded(Callable). The point of this over new Thread() { ... }.start() is that this uses a thread pool.

Parameters:
thunk -
Throws:
kilim.Pausable

runPausable

public static void runPausable(Token caller,
                               Kilim.PausableCallable<? extends java.lang.Object> thunk)
Utility method to run a pausable computation which generates a value for a token.

Parameters:
caller - token to return the value to
thunk - computation returning a value