[Gambas-user] Multi threaded apps

Ron ron at ...1740...
Sat Sep 6 13:15:43 CEST 2008


Benoit Minisini schreef:
> On samedi 06 septembre 2008, Doriano Blengino wrote:
>   
>> Pino Zollo ha scritto:
>>     
>>> Alle 19:11, venerdì 5 settembre 2008, nando ha scritto:
>>>       
>>>> This thread would cease to exist when the SUB is completed.
>>>> The main thread continues processing along side this one.
>>>>
>>>> The interpreter would have to switch running threads regularly.
>>>>         
>>> I guess that there should be many instances of the interpreter, one for
>>> thread. Hope the interpreter is light enough !
>>> Very nice and usefull to have !
>>>       
>> Threads share their dataspace (otherwise they are no more threads, but
>> processes instead). If two or more interpreters share the same data,
>> then a lot of problem arise - the whole event system breaks, because
>> there is concurrent access to the same structured data which, at a
>> certain point, can loose its integrity (both the data structures managed
>> internally by gambas, and the user ones...). If we want threads, then we
>> also have to use locks, semaphores, priorities and other difficult
>> things. Nando's idea is a lot easier to put in practice: at least,
>> internal data structures are safe, but still is a big task. Then, the
>> user gets a lot of responsabilities... what if, while one thread uses a
>> FOR EACH on a collection, another thread deletes it?.
>>
>> I think the easiest way is to have an "Idle event" - an event fired
>> everytime there is nothing else to do. In the Idle event handler, one
>> can run many background jobs. May be this is already possible using a
>> timer with very short interval (zero?), but this is not the intended
>> usage of timers.
>>
>>
>> Happy coding to all,
>> Doriano Blengino
>>
>>
>>     
>
> Gambas interpreter was not designed to be multi-threaded at all.
>
> What sort of background process people want to do during their application? I 
> never had such a need.
>
> Regards,
>
>   

My home automation program does a lot of things 'at the same time'

To give you an idea what it does already:
parse and writing sensor (now about 50) data to a mysql database, like 
temp, humid, door/window open close, dark/light etc
saving selected sensor data to rrdtool databases, and create rrdtool 
graphs of sensor data
have several sockets open, like
  rfxcom receiver (receives and process sensor data)
  asterisk api socket (gets phone call status), and logs missed calls
  hddtemp socket, gets harddrive temps,
  upsd socket, gets ups stats like status and mains voltage
have a main loop running every 250mS to calculate things and runs scripts to
process data and set vars like season, sunrise, moonphase every second, 
minute, hour, year depending on type.
so i can start things only if a new_minute is active for example
scans for my bluetooth devices to see if i'm at home (wip)
reads several serial interfaces (1-wire sensors, gps, sms modem etc)
gui handling for managing sensor devices etc
fetch rss feed
it also has a small webserver buildin, to look at program data over the 
internet, but haven't got it to run 100% ok yet
it grabs camera captures when mailbox sensor is activated.
what i need to add, is an xmlrpc server (if I only knew how this 
component works) anyone has a code snippet?
an event scheduler stored in mysql table, for scheduled events like, 
lamp on of every evening (now hardcoded)

some data input is triggered because the device sends it every now and 
then, some data is polled for every x seconds
so for some parts multi-threading would be a bless...
but it's now still a single user standalone program,  i could/should 
take it apart, and get the logging part seperate (server), from the gui 
part (client)

Regards,
Ron_2nd






More information about the User mailing list