Author Topic: Lightweight threading in C++  (Read 4862 times)

lardman

  • Hero Member
  • *****
  • Posts: 4512
    • View Profile
    • http://people.bath.ac.uk/enpsgp/Zaurus/
Lightweight threading in C++
« 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
C750 OZ3.5.4 (GPE, 2.6.x kernel)
SL5500 OZ3.5.4 (Opie)
Nokia 770
Serial GPS, WCF-12, Socket Ethernet & BT, Ratoc USB
WinXP, Mandriva

doublec

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
    • http://radio.weblogs.com/0102385/categories/zaurus/index.html
Lightweight threading in C++
« Reply #1 on: January 14, 2004, 03:22:55 pm »
You can use the libpthreads library:

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

Chris.

lardman

  • Hero Member
  • *****
  • Posts: 4512
    • View Profile
    • http://people.bath.ac.uk/enpsgp/Zaurus/
Lightweight threading in C++
« Reply #2 on: January 14, 2004, 04:42:04 pm »
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
C750 OZ3.5.4 (GPE, 2.6.x kernel)
SL5500 OZ3.5.4 (Opie)
Nokia 770
Serial GPS, WCF-12, Socket Ethernet & BT, Ratoc USB
WinXP, Mandriva

doublec

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
    • http://radio.weblogs.com/0102385/categories/zaurus/index.html
Lightweight threading in C++
« Reply #3 on: January 14, 2004, 04:57:55 pm »
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.

lardman

  • Hero Member
  • *****
  • Posts: 4512
    • View Profile
    • http://people.bath.ac.uk/enpsgp/Zaurus/
Lightweight threading in C++
« Reply #4 on: January 15, 2004, 06:33:52 am »
Thanks for the info.

Si
C750 OZ3.5.4 (GPE, 2.6.x kernel)
SL5500 OZ3.5.4 (Opie)
Nokia 770
Serial GPS, WCF-12, Socket Ethernet & BT, Ratoc USB
WinXP, Mandriva