views:

60

answers:

4

Hi folks.

I don't want to reinvent the wheel, and what I'm looking for most likely already exist in the FOSS world.

I'm looking for a pthread bases utility library that implements often used primitives to do communication between threads.

My main need is some kind of blocking queue for fixed size messages and the ability to wait for data to arrive on multiple queues at the same time (what you usually do using poll and select with file-handles).

Does something like this exist?

Programming language is C++ but I'm fine with a C library. OS is Linux but anything posix will do.

EDIT

I'm not looking for a thin wrapper around pthreads (like boost::thread or so). I already have this up and running. I'm looking for higher level primitives. Basically What java.util.concurrancey offers for the java guys.

A: 

You could try OpenMP, though I'm not sure whether it's based on the pthread API or not.

Kedar Soparkar
OpenMP is not what I'm looking for. It'll help me to parallize programs. My program is already using threads, but the glue code to pass messages/data between threads is what I'm looking for. (my glue-code works, but in the long run I need something better)
Nils Pipenbrinck
A: 

For what programming language / environment?

Some options:

Piet Delport
+2  A: 

Your requirements are already baked into POSIX Message Queues.

Instead of using select() you can do it in reverse. Rather than waiting in a select() you can use mq_notify() to tell you when there is something to read. MQs give you the option of having a signal delivered or having them spawn a new thread to read the queue.

If you are really intent on using select(), Linux makes this painless since the mqd_t type is actually a file descriptor. You can simply use the mqd_t returned from mq_open() like any other FD in select().

Note that use of a mqd_t in select() is not portable. In theory you should be able to do something similar on other systems but I have never tested it. Since POSIX MQs have a path to an entry to the filesystem you should be able to do a straight open() on the path and use the returned file descriptor in the select(), mapping it to the mqd_t used in mq_open() to determine which queue to read. Again, I have never tried it.

Duck
+1  A: 

There's always boost::thread.

DeadMG