[fpc-pascal] Actor Model implementation in Pascal
Jorge Aldo G. de F. Junior
jagfj80 at gmail.com
Sun Mar 13 22:59:32 CET 2011
the actor model can accelerate tasks that would be dealt with in
singlethreaded fashion...
lets suppose that your program needs to read 8 files at the same time,
pre-process them, and use their data.
you can write an actor that opens the file and pre-process it
in your main thread (the program itself, wich is a thread of sorts,
even if not being a TThread) you start 8 of those actors and sit in a
loop waiting for then to produce a message.
your 8 actor instances will, each one, pre-process the data to you.
if your end-user happens to have a multi-core processor, the end
result is that your 8 actors will finish faster than if you used only
one thread to deal with each one of the 8 files...
what i mean is that, under current processor technology, the actor
model is a way to simplify the usage of threads, without the
complexities of locks, semaphores and the like.
you just pass messages around, wich, in the case of my little library,
are just plain tobject descendents...
2011/3/13 Sven Barth <pascaldragon at googlemail.com>:
> Am 13.03.2011 22:30, schrieb Jorge Aldo G. de F. Junior:
>>
>> yes, its a kind of message passing.
>>
>> but mine is in native pascal and i have no intention of making
>> bindings for other languages...
>>
>> its wayyy simpler than mpich too. you just pass TObjects back and
>> forth from threads.
>>
>> (I understand that TCustomMessage is way too restrictive, so i am
>> planing to develop a kind of interface based model, so you can pass
>> arbitrary objects around).
>>
>> it simplyfies thread programming a lot, at a cost of a little overhead.
>>
>> the switchboard (the thing that routes messages between threads) is
>> itself a class factory, so your threads can start/stop other threads
>> (called 'actors" in this context) and send message to them.
>>
>> the default actor implementation is event based, where the class name
>> of the object received triggers an dispatchstr... but i am looking for
>> other ways to deal with message receiving.
>>
>> if you dont like this model you can override TActorThread.Execute and
>> do business your own way...
>>
>> As it is a simple implementation in native pascal, theres no concept
>> of security or whatever.
>>
>> later i can add blowfish encryption to the TCP/IP part of the thing
>> and message authentication using SHA1
>>
>> (TCP/IP streaming of messages across machines, for this little library
>> "Pascal-Actor-Model", is the reason behind so many questions i've sent
>> to this mailing list about multi-threading, blowfish and SHA1
>> encryption...)
>
> I might look at this once I have a usecase for it (currently I have rather
> single threaded problems to solve :P ). Thank you for sharing, though.
>
> Regards,
> Sven
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list