At Sat, 6 Sep 2014 19:58:02 +0800, =?utf-8?B?QmluZ3BlbmcgWmh1?= wrote: > > [1 <multipart/alternative (8bit)>] > [1.1 <text/plain; utf-8 (base64)>] > Hi, Yuan > Thanks very much for your reply. Actually, I am confused by the code in > function worker_routine() in /lib/work.c . > In file /lib/work.c of the master branch: > > > Line 317: sd_mutex_lock(&wi->startup_lock); > Line 318: /* started this thread */ > Line 319: sd_mutex_unlock(&wi->startup_lock); > > > > I don't understand the purpose for lock wi->startup_lock and unlock it > immediately. Seems it wants to block the new thread here until all the new > threads are created when the thread pool need to grow.
The lock is a historical garbage. The code of worker threads is imported from tgt (https://github.com/fujita/tgt) and the corresponding code in tgt is removed in a recent commit (https://github.com/fujita/tgt/commit/c57e3ba1ae043eff558b4534e5bfe0c7865f6c1e). Feel free to send a patch for removing the lock if you have time :) Thanks, Hitoshi > > > Thanks! > Bingpeng > > > > > ------------------ 原始邮件 ------------------ > 发件人: "Liu Yuan";<namei.u...@gmail.com>; > 发送时间: 2014年9月4日(星期四) 上午10:07 > 收件人: "Bingpeng Zhu"<nku...@foxmail.com>; > 抄送: "sheepdog"<sheepdog@lists.wpkg.org>; > 主题: Re: [sheepdog] quesiton about function worker_routine() in lib/work.c > > > > On Wed, Sep 03, 2014 at 05:37:19PM +0800, Bingpeng Zhu wrote: > > Hi, all > > I am reading sheepdog's source code. I have a question of the code in > > function worker_routine() in lib/work.c. > > It calls sd_mutex_lock(&wi->startup_lock) in the beginning , and calls > > sd_mutex_unlock(&wi->startup_lock) ��> > immediately after the lock. It > > seems that the code want to block the new threads until all the new threads > > are created. > > I don't understand the purpose for doing this. Can anybody answer my > > question? > > > > We have tow concepts in thread pool mechanism, workers and main thread, so > normally the task would be split into two parts, one can be executed in > paralle > in different thread context, and the other can be executed in the main thread > sequentially. > > worker pool > > thread 1 ---- run someone's job1 in worker thread > thread 2 ++++++++++++++++++++ run some other's job2 > thread 3 **** idle ************** > .... > job 1 worker finishes and queue to run something in main thread > | > V > main thread =====---============++++========= > | > v > job2's main part > > In this way, if job1 and job2 has something that need to run sequentially, > then > we can put those sequential action in main thread. > > work.fn will run in worker pool in parallel with other jobs > work.done will run in main thread sequentially > > Thanks > Yuan > [1.2 <text/html; utf-8 (base64)>] > > [2 <text/plain; us-ascii (7bit)>] > -- > sheepdog mailing list > sheepdog@lists.wpkg.org > http://lists.wpkg.org/mailman/listinfo/sheepdog
-- sheepdog mailing list sheepdog@lists.wpkg.org http://lists.wpkg.org/mailman/listinfo/sheepdog