I implemented a scripting language, Dao, which is released as 1.0-beta
version some days ago. Dao supports concurrent programming by providing
native thread, mutex and semahpore types; it also provides coroutines
as an additional concurrent facility. I believe concurrent computing
will become more and more important in the future, so I would like to
add more concurrent programming ability to this new language.
The first thing I could do is to add to Dao some new language
constructs such as "parbegin ... end", to allow statements or blocks in
their between being executed parallelly. That is essentially the same
as using threading library, and do not simplify concurrent programming.
It may be useful for parallel numerical computing, but not suitable to
construct complex concurrent system. So I looked around for high level
concurrent computing models, and found the Actor Model, which seems to
be most attracting to me. After reading something about this model, I
feel I got some ideas on how to add this concurrent model to Dao. I
have list those rough ideas below to seek suggestions from you.
I should admit I am extremely new to this field (actually got to know
this field since yesterday;-) ), so the first thing I would like to
know is that, is there any flaw in the ideas I list below?
Secondly, is it really necessary to add language constructs into Dao
for such type of concurrent computing (such as statement named "send
..." ect.)? Since I found these ideas could be implemented as a package
in Dao language itself using the native threading library. But adding
language constructs may render this new langauge more attractive, this
is one factor I will take into consideration;-)
Thanks a lot!
The Rough Ideas:
Features in the Dao language that are useful for implementing
concurrent system (using threads within single OS process) based on
1. native threading;
2. function overloading by parameters;
3. callable class instance with "_CALL" methods that overload function
call operator "(...)".
Actors should be callable objects:
functions, function closures, class instance with "_CALL()" methods,
wrapped C functions, wrapped C types with "_CALL()" methods.
Any Dao data types.
send( mode, actor, msgObj1, msgObj2, ... )
mode: can be asynchronous or synchronous.
For real time system it can also be used to indicate that the actor
must respond to
the messages immediately, bypassing the underlying message queue.
actor: the receiver, identified by memory address within the same OS
msgObj1, msgObj2, ...: the message;
Re-acting to message:
In response to message, actors are called:
actor( msgObj1, msgObj2, ... );
If the actor is an overloaded function, the function with parameter
types matching to message objects are called. If the actor is a class
instance with overloaded "_CALL" methods, similarly the one with
matching parameters is called. In this way, different behaviors of the
same actor can be implemented as different functions or methods, and
the virtual machine of Dao will choose the right one based on the types
of the message objects.
Note: the drawback of this, exception handling is not yet imple