OESF Portables Forum
General Forums => Off Topic forum => Topic started by: lardman on January 14, 2004, 12:19:41 pm
-
Hi,
I\'m after any recommendations as to how I should do lightweight threading (i.e. \'tasks\' - callback functions - all in a single thread/process).
My basic problem is a lack of understanding of how I can create and receive events (like a keypress, a timer expiry, or even a fake event to allow a large task to start running again).
My plan is to have a single input event (keypress/pointer) task/function, a timer driven UDP output task, a timer driven UDP input task, and a continuously running (when the other tasks aren\'t - lower priority) calculation task. This is for an autopilot programme BTW.
I\'ve done all of this stuff on the Psion, but have no idea as to how events work in Linux.
Anyone have any ideas as to where I should look.
Thanks,
Si
-
You can use the libpthreads library:
http://www.humanfactor.com/pthreads/ (http://www.humanfactor.com/pthreads/)
Chris.
-
How lightweight are these? They look like proper user-space threads (though I may be wrong, I\'ll take a look at the docs).
How\'s about some links to event driven programming (which is really what I\'m after I suppose).
Si
Si
-
For lightweight threads you\'ll need to use \'select\' or \'poll\'. I\'m not sure if the Zaurus has the latter. Basically you use call \'select\' passing it an array of file descriptors you want to monitor for activity and a timeout. This function will return the descriptor that requires a read/write or whatever other event, or an note that it timed out. Most lightweight thread implementations use this.
-
Thanks for the info.
Si