Changes by: Jason Hickey (jyh at cs.caltech.edu)
Date: 2004-06-09 11:38:01 -0700 (Wed, 09 Jun 2004)
Revision: 384
Log message:
This modifies the infrastructure for threads. Here is the model:
1. Each thread has a current state, and each state has a set
of global variables.
2. State variables must be locked before being used.
3. State variables come in two types: shared and private.
Each state has its own copy of the private variables.
For example, each job in the shell has its own state, and its
own copy of the Shell.info struct. States are managed implicitly,
so global variables look just like global variables. Access is
managed with the State.read/State.write routines.
Here is an example of usage for a shared variable:
let global_entry = State.shared_val "debug" (ref 0)
let get () =
State.read global_entry (fun x -> !x)
let incr () =
State.write global_entry (fun x -> x := !x + 1)
For private variable, you have to supply a "fork" function that
is used to copy the value. Each thread/state will have its own copy
of the variable. The other functions remain the same.
let global_entry = State.shared_val "debug" (ref 0) (fun x -> ref !x)
All the State.* functions are wrappers that take a function argument. The
value is locked on entry into the function, and unlocked when the function exits.
Exceptions are handled correctly.
Don't use Mutex if you can help it!!! The Mutex functions do not
handle exceptions correctly. Use the State module instead.
NOTES:
1. I removed the Java interface... It was just getting to be too much
of a hassle. We can ressurect it if we ever want it again.
2. This is just the infrastructure pass. The global values used by the
browser need to be updated to the new model.