[Gambas-user] Gambas is not multi-threaded, but... (fixed version)

Benoît Minisini gambas at ...1...
Sat Aug 25 00:41:31 CEST 2012


Hi,

In revision #5076, I added a new gb.task component that allows you to 
run a class in the background.

Internally, the interpreter is "simply" forked. But it's not that 
simple. :-)

How does it work?

Once gb.task is checked in the IDE, you get a new class named "Task".

To run a class in the background:
- That class must inherit Task.
- It must have a public "Main" method that takes no argument and returns 
nothing. That method will be run in the background.

Instanciate the class, and it will be run automatically as soon as the 
event loop is run.

The task object will raise a "Kill" event when it has been terminated.

You can wait for the end of a task by using its Wait() method.

You can stop a task by calling its Stop() method.

You can get the process id of a task with its Handle property.

As the method is run by a fork, it has access to every other part of the 
program, except that the main process that run the task will not see any 
change done by the task of course.

The main process can simply modify some public variables in the task 
class to define the arguments of the task. But allowing the task to talk 
to the main process to give the result of its work is not done yet.

Maybe the task Main() method will have a Variant return value that will 
be transparently serialized, sent to the main process, and deserialized.

Or maybe the standard output of the task will be redirected to a pipe 
read by the main process.

Or maybe the both solutions... I don't know yet.

Another point. I don't think that gb.qt4 or gb.gtk will be usable inside 
a fork. I didn't try. But background tasks should normally be used 
for... background invisible tasks.

Tell me what you think about all that!

Regards,

-- 
Benoît Minisini




More information about the User mailing list