OESF | ELSI | pdaXrom | OpenZaurus | Zaurus Themes | Community Links | Ibiblio

IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Lightweight threading in C++
lardman
post Jan 14 2004, 09:19 AM
Post #1





Group: Members
Posts: 4,515
Joined: 25-October 03
From: Bath, UK
Member No.: 464



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
Go to the top of the page
 
+Quote Post
doublec
post Jan 14 2004, 12:22 PM
Post #2





Group: Members
Posts: 92
Joined: 2-January 04
Member No.: 1,338



You can use the libpthreads library:

http://www.humanfactor.com/pthreads/

Chris.
Go to the top of the page
 
+Quote Post
lardman
post Jan 14 2004, 01:42 PM
Post #3





Group: Members
Posts: 4,515
Joined: 25-October 03
From: Bath, UK
Member No.: 464



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
Go to the top of the page
 
+Quote Post
doublec
post Jan 14 2004, 01:57 PM
Post #4





Group: Members
Posts: 92
Joined: 2-January 04
Member No.: 1,338



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.
Go to the top of the page
 
+Quote Post
lardman
post Jan 15 2004, 03:33 AM
Post #5





Group: Members
Posts: 4,515
Joined: 25-October 03
From: Bath, UK
Member No.: 464



Thanks for the info.

Si
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 20th September 2014 - 02:06 PM