Efficiently Handling Job Queue and Thread Signaling in a Cross-Platform Thread Pool Library in C
I am trying to make a cross platform threadpool library in c.
The thing that I don’t understand is that for example if I have 4 threads in the threadpool and I give all 4 of them work to do and its going to take a long time, in this case 1 minute, if I add 20 jobs into the jobqueue before the 1 minute mark, all 20 function call will signal for threads when they add anything into queue but no thread will be able to get that signal (as no threads are waiting for any signals). And the signal would be lost. When any of the threads are free they will wait indefinitely because there would be no more signals as all jobs are already in the queue.
synchronization in multithreading in c
I am trying to make a cross platform threadpool library in c.
The thing that I don’t understand is that for example if I have 4 threads in the threadpool and I give all 4 of them work to do and its going to take a long time, in this case 1 minute, if I add 20 jobs into the jobqueue before the 1 minute mark, all 20 function call will signal for threads when they add anything into queue but no thread will be able to get that signal (as no threads are waiting for any signals). And the signal would be lost. When any of the threads are free they will wait indefinitely because there would be no more signals as all jobs are already in the queue.