worker thread queue (or thread pool) in C under linux?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
worker thread queue (or thread pool) in C under linux?
I'm porting some code I wrote that uses the Win32 api to linux. Is there a worker thread queue api or library in linux? I'd like to find something similar to the Win32 QueueUserWorkItem, since I'd rather not roll my own thread queue.
There's an intel project under GPL called Threading Building Blocks, but it's a C++ library. I also found libcprops, but the project doesn't seem to be maintained and doesn't actually implement a queue, just a pool. Finally there are kernel workqueues (linux/workqueue.h), but these seem to be made with kernel space driver code in mind. Would they work in a userspace program?
Can anyone point me to a library or api that will let me schedule jobs to be run by a pool of threads with a fixed size?
Can anyone point me to a library or api that will let me schedule jobs to be run by a pool of threads with a fixed size?
Thanks!
AFAIK there are no such equivalent set of APIs that are de facto in the linux world. I am not familiar with the projects you referenced, but depending on your needs, implementing pthread pool may not be complex undertaking IMHO. At the other end of the spectrum, there is the open-source resource manager Simple Linux Utility for Resource Management (SLURM) which has a plug-in job scheduler if that is what you are looking for.
Thanks for the links, both of you. I'm somewhat familiar with both pthreads and Boost. My impression was that they would both be decent starting places if I wanted to implement a thread pool myself, but this is exactly what I'm trying to avoid. SLURM seems way too heavy.
The program I'm porting has a section where it runs some functions that traverse a 3D dataset where the columns and planes can alternatively be processed independently. The idea of the thread pool was to amortize the creation cost of threads created to process the rows/cols across many jobs. I assume you guys know that's what I was getting at by your answers, but I suppose a little clarification never hurts. Anyway, I'm looking for speed here, since this happens at video rates, on a single system. (I have a system with many cores, large dataset, etc). I'm no threading expert, so I could see myself easily spending a week creating my own pthreads work queue and debugging it. Do you know any example code for something like this? It seems hard to believe that no one is doing this in C in linux. Or is it easier than I'm thinking?
I'm porting some code I wrote that uses the Win32 api to linux. Is there a worker thread queue api or library in linux? I'd like to find something similar to the Win32 QueueUserWorkItem, since I'd rather not roll my own thread queue.
There's an intel project under GPL called Threading Building Blocks, but it's a C++ library. I also found libcprops, but the project doesn't seem to be maintained and doesn't actually implement a queue, just a pool. Finally there are kernel workqueues (linux/workqueue.h), but these seem to be made with kernel space driver code in mind. Would they work in a userspace program?
Can anyone point me to a library or api that will let me schedule jobs to be run by a pool of threads with a fixed size?
You can check my implementation of a thread pool on github or sourceforge. What makes it more helpful than the previous posts is that it has full documentation of design and usage.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.