[PATCH] Fix a pthreadpool race

Ralph Wuerthner ralphw at de.ibm.com
Fri Dec 15 11:17:07 UTC 2017


Hi Volker!

On 07.12.2017 07:59, Volker Lendecke via samba-technical wrote:
> Attached patch has the very nice explanation in the commit message. It
> also removes the necessity for the preliminary patch. Runs in a
> private autobuild now. I'll push once this survived and nobody objects
> in the meantime.

Maybe I'm a little bit late, but please take a look at my attached patch 
set. It fixes the job-starvation-after-fork race without introducing a 
new mutex. By moving the check on pool->prefork_cond in front of the 
pthread_cond_timedwait() call on pool->condvar the thread will continue 
with processing jobs. Threads will only be killed if the job queue is empty.

I addition I wrote a new test case to test this scenario with multiple 
threads running in parallel and doing a fork with jobs sitting on the 
job queue and doing a 2nd fork when only idle threads are around. One 
todo for this test case would be to add a check that all idle threads 
are gone after the 2nd fork. Unfortunately I didn't found a portable 
solution without checking /proc/<pid>/task or running a ps command. 
Maybe somebody else on this list has a clever idea.

The patch set applies on master.

-- 
Regards

    Ralph Wuerthner
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-job-starvation-after-fork-race.patch
Type: text/x-patch
Size: 11965 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20171215/78afc739/fix-job-starvation-after-fork-race.bin>


More information about the samba-technical mailing list