Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-03

Actor Model implementation in Pascal

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jorge Aldo G. de F. Junior

This is my attempt at implementing an actor model in freepascal

http://code.google.com/p/pascal-actor-model/

This is an very early code. Any help is appreciated.

Every communication between thread is done by using messages (wich are itself objects).

I am improving the current code a bit so this EXACTLY release maybe dont compiles.

If you want to compile the test code, simply create dummy procedure/functions for anything that the compiler complains about not being implemented.

The base code works, i am just trying to implement a form of message/object streaming to allow threads to communicate across TCP/IP and not just by using the internal switchboard queues.

Reply by email

Sven Barth
to Jorge Aldo G. de F. Junior
Jorge Aldo G. de F. Junior wrote
This is my attempt at implementing an actor model in freepascal

Never heard of "actor model" yet, but I'll read about it ^^

Show quoted text 17 lines
http://code.google.com/p/pascal-actor-model/ This is an very early code. Any help is appreciated. Every communication between thread is done by using messages (wich are itself objects). I am improving the current code a bit so this EXACTLY release maybe dont compiles. If you want to compile the test code, simply create dummy procedure/functions for anything that the compiler complains about not being implemented. The base code works, i am just trying to implement a form of message/object streaming to allow threads to communicate across TCP/IP and not just by using the internal switchboard queues.

Do you mean something like this? http://wiki.lazarus.freepascal.org/MPICH

Regards,
Sven

Reply by email

Jorge Aldo G. de F. Junior
to Sven Barth

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...)

2011/3/13 Sven Barth :

Show quoted text 33 lines
Am 13.03.2011 22:08, schrieb Jorge Aldo G. de F. Junior: > > This is my attempt at implementing an actor model in freepascal > Never heard of "actor model" yet, but I'll read about it ^^ > http://code.google.com/p/pascal-actor-model/ > > This is an very early code. Any help is appreciated. > > Every communication between thread is done by using messages (wich are > itself objects). > > I am improving the current code a bit so this EXACTLY release maybe > dont compiles. > > If you want to compile the test code, simply create dummy > procedure/functions for anything that the compiler complains about not > being implemented. > > The base code works, i am just trying to implement a form of > message/object streaming to allow threads to communicate across TCP/IP > and not just by using the internal switchboard queues. Do you mean something like this? http://wiki.lazarus.freepascal.org/MPICH Regards, Sven _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Sven Barth
to Jorge Aldo G. de F. Junior
Jorge Aldo G. de F. Junior wrote 35 lines
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

Reply by email

Jorge Aldo G. de F. Junior
to Sven Barth

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 :

Show quoted text 47 lines
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  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Sven Barth
to Jorge Aldo G. de F. Junior

Yes, that sounds indeed interesting (well... most multithreading things do ^^), but...

Jorge Aldo G. de F. Junior wrote 11 lines
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.

... do you mean active waiting here?

Show quoted text 14 lines
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...

Regards,
Sven

Reply by email