c++ multithreaded task queue for scheduled tasks

匆匆过客 提交于 2019-12-12 10:14:13

问题


I need to develop a module which will execute scheduled tasks.
Each task is scheduled to be executed within X milliseconds.

The module takes as a parameter an amount of worker threads to execute the tasks.

The tasks are piled up in a queue which will probably be a priority queue, so a thread checks for the next-in-queue task (the one with the lowest "redemption" time), thus there's no need to iterate through all tasks each time.

Is there any public library that does that or shall I roll my own?

Note: I'm using VC2008 on Windows.


回答1:


If you don't mind a Boost dependency, threadpool might fit your needs.




回答2:


Take a look at TBB - Intel Threading Building Blocks.




回答3:


Just to add a little information to your question, what you're asking for is a real-time scheduler that uses the Earliest Deadline First algorithm. Also note that without OS support, you can't guarantee that your program will work in that X millisecond deadline you assign it. The OS could always decide to swap your task off its CPU in the middle of the job, making it take an unpredictably-long time to complete.

If your application critically depeneds on the task being done in the X milliseconds you set for it (or something blows up), you'll need to be running a real-time operating system, not regular Windows.



来源:https://stackoverflow.com/questions/3273455/c-multithreaded-task-queue-for-scheduled-tasks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!