I'm having to use an API that uses Facebook Folly Executor library. Tasks (functions) are pushed into a queue, then threads in the thread pool run whatever available task.
But in case the pool only has 1 single thread, what happens? For example this case:
Global init: atomic<int> x = 0
Job 1: while(x != 1) {}
Push job 1 into thread pool queue
Job 2: x = 1;
Push job 2 into thread pool queue
When lauching 2 std::thread
manually, the program works as expected and does not have any deadlock or undefined behavior. However, what happens in this case when these 2 jobs are pushed into a thread pool with only 1 thread? If it's concurrent then all is fine, but if jobs in the queue must be completed in the correct order then i'll deadlock.
Are there any general guidance on how a thread pool library should behave in this case?