tags:

views:

346

answers:

5

I am looking for user-mode multi-threading library/framework for C++ under Linux. I am familiar with boost::thread and ACE_Thread_Manager but AFAIK both of them eventually use OS native thread's support.

Suggestions will be highly appreciated.

+6  A: 

GNU PTH: http://www.gnu.org/software/pth/

It's using cooperative multithreading, which is why it's used in GnuPG (which for security reasons doesn't want real threads, but for responsiveness reasons needs threads).

"The intention is that this way one can achieve better... run-time performance than with preemptive scheduling" - unless of course your machine has more than one core.
Daniel Earwicker
My machine has once core - actually the application is running on embedded device. All those links provide tons of reading material(I not complaining). Thank you for your answers.
error.exit
@Earwicker: If your throughput demands can be met with a single core, then task switching, cacheline stealing, locking overhead and stuff like that is very likely to make your program run _slower_ with native multithreading than with cooperative, single-thread "multi"threading.
+2  A: 

Is MTasker the kind of thing you're looking for? It's also a cooperative multi-tasking library. You might also want to consider just whipping up some state machines.

Also check out State Threads and MIT Pthreads.

This tool will assist in the generation of hierarchical state machines, which could be used for this purpose: CHSM

Gabe
I've followed your links and it looks interesting (I liked the CHSM). Need more time to puzzle it out. Thank you.
error.exit
+1 for CHSM (interesting, even though OT). Boost.StateChart can do similar things (is there anything that's not in Boost? :)
A: 

You may want to check out Intel Thread Building Blocks. (TBB)

http://www.threadingbuildingblocks.org/

It tries to abstract a lot of the threading concepts away from the programmer while having he/she take more of a task based approach to parallelism.

RC
+1  A: 

If you want to thread for io type operations you could consider multi-plexing with select

Matt Price
+1  A: 

I blogged on this topic a while back: http://yz.mit.edu/wp/cooperative-threads-for-cc/.

At the time I had compared the front-runners State-Threads and GNU Pth, and based on not-too-careful examination of the documentation and code, I walked away with greater confidence in the systems hackery in ST than Pth, but I can't recall the specifics. I've had a positive experience with ST, so never really tried out Pth.

The only thing that worried me about ST is its disclaimer about its (inability to) interop with pthreads. I had used both in the same project (another reason why Pth probably doesn't fit the bill is that it uses all the same symbol names as pthreads), and I never ran into any issues, but I never stress-tested the combination.

Would be interested in knowing your (and others') experiences WRT these two particular libraries.

Yang