[Gambas-user] Multi threaded apps

Doriano Blengino doriano.blengino at ...1909...
Sat Sep 6 11:13:23 CEST 2008


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





More information about the User mailing list