You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to make a cross platform threadpool library in c and I came across this library and I started to examine it but I don't get it how is it working.
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 work into the queue before the 1 minute mark, they all will signal for threads but no one will be able to get that signal (as they are not waiting for any signal) and miss the signal and then I noticed that you added an integer v in bsem because of it it will take atleast one job after the first initial intensive job but then after this how does the thread know if there are any jobs left in the queue. There is no signal to inform the threads and the integer v is 0 after taking the 2nd job.
I tried this library in linux because of signals .I made the above mentioned scenario, and it still worked. I don't get it how is it working.
Any help would be appreciated.
The text was updated successfully, but these errors were encountered:
When we add work, the jobqueue will post one bsem, so the first thread can pull the job from the front of the jobqueue. Notice that the function jobqueue_pull includes a switch check:
switch(jobqueue_p->len){
case 0: /* if no jobs in queue */
break;
case 1: /* if one job in queue */
jobqueue_p->front = NULL;
jobqueue_p->rear = NULL;
jobqueue_p->len = 0;
break;
default: /* if >1 jobs in queue */
jobqueue_p->front = job_p->prev;
jobqueue_p->len--;
/* more than one job in queue -> post it */
bsem_post(jobqueue_p->has_jobs);
}
If the current length of the jobqueue is greater than 1, the jobqueue will post another bsem, allowing the second thread to take the job from the jobqueue.
This is the reason why the thread know if there are any jobs left in the queue.
I am trying to make a cross platform threadpool library in c and I came across this library and I started to examine it but I don't get it how is it working.
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 work into the queue before the 1 minute mark, they all will signal for threads but no one will be able to get that signal (as they are not waiting for any signal) and miss the signal and then I noticed that you added an integer v in bsem because of it it will take atleast one job after the first initial intensive job but then after this how does the thread know if there are any jobs left in the queue. There is no signal to inform the threads and the integer v is 0 after taking the 2nd job.
I tried this library in linux because of signals .I made the above mentioned scenario, and it still worked. I don't get it how is it working.
Any help would be appreciated.
The text was updated successfully, but these errors were encountered: