Each horizontal bar is a task that represent a pair of turn-on and turn-off operations on a valve. A task does the following: wait for Y ms, turn on valve 1, wait for X ms, then turn off valve 1. This is a real-time system where the duration of each task, when and if a new task is coming varies.
Since each task is a blocking operation that can be run in some background thread, I used
GTask to run each task in a worker thread. The problem occurs when a large number of tasks arrive in short succession, when this happens, the thread pool runs out of worker threads very quickly, and incoming tasks are delayed which lead to the valve being turn on/turn off at the wrong time. The thread pool runs out of worker threads even faster when there are more than one valve in the system.
I want to ask if the use case described above is actually unsuitable for GTask? And if GTask is not the answer, what approach you recommend?