c++ multithreaded task queue for scheduled tasks

2019-06-07 08:51发布

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.

3条回答
该账号已被封号
2楼-- · 2019-06-07 09:04
Ridiculous、
3楼-- · 2019-06-07 09:04

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.

查看更多
相关推荐>>
4楼-- · 2019-06-07 09:11

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

查看更多
登录 后发表回答