There's no significant functionality in the M3 interface that's not
in <pthread.h>. It's just a much nicer integration with the language,
and a python thread interface could do the same sort of thing.
The Modula-3 interface looks something like (don't have a book handy):
INTERFACE Thread;
TYPE T <: REFANY; (* represents a thread *)
TYPE Mutex = MUTEX; (* built into the language; <: ROOT *)
TYPE Condition <: ROOT;
TYPE Closure = OBJECT METHODS
apply() : T; (* spawn a thread *)
END;
EXCEPTION Alerted;
PROCEDURE Acquire(m : Mutex);
PROCEDURE Release(m : Mutex);
PROCEDURE Wait(c : Condition; m: Mutex) RAISES Alerted;
PROCEDURE Join(thread: T);
PROCEDURE Alert(thread: T);
END Thread.
Plus there's a LOCK statement:
LOCK m DO
...
END
that's equivalent to:
Thread.Acquire(m); TRY
...
FINALLY
Thread.Release(m);
END
The idea is that if you've got some data you want to protect with
a mutex, you can do:
IMPORT Thread
TYPE Precious = Thread.Mutex OBJECT
data : INTEGER;
END;
VAR p : Precious;
LOCK p DO
INC(p.data)
END
in python, I expect it would look something like:
import Thread
from Thread import LOCK, END
class Precious(Thread.Mutex):
def __init__(self, n):
self.data = n
p = Precious(10)
LOCK(p); try: # or better yet, add lock statement to grammar
p.n = p.n + 1 # is there a ++ equiv in python?
finally: END(p)
Daniel W. Connolly "We believe in the interconnectedness of all things"
Software Enginner, Hal Computer Systems (512) 834-9962 x5010
<connolly@hal.com> http://www.hal.com/%7Econnolly/index.html