Re: Question about dec_lock_cnt method in Context class
Adam Lackorzynski <[email protected]>
| Newsgroups | gmane.comp.micro-kernel.l4.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, On Tue Sep 09, 2014 at 17:18:16 -0400, Yuxin Ren wrote: > There are three places where "_running_under_lock" is set to true; > > First one is just in the above loop. So this code will run only after it > goes into the loop. > This does not help explain why the code can go into the loop. > > The second is in Context::running_on_different_cpu() method in context.cpp > file. > if (EXPECT_FALSE(lock_cnt()) > && EXPECT_FALSE(!mp_cas(&_running_under_lock, Mword(false), > Mword(true)))) > return true; > But this only happens when lock_cnt is non-zero. > > The third one is in Context::need_help method in context.cpp file. > The method is called only when a thread tries to help the lock holder. > I think this implies that the lock holder holds a lock and as a result, its > lock_cnt is not 0. > > Just from those code, I think it is impossible for a thread that its > "_running_under_lock" is true while its lock_cnt is 0. > However now that the code is here, I want to know why the author add the > "extra" check here? > The author should have some reason to do so, right? Yes, probably. I can just give a fuzzy answer but the new release (due soon) will have a few changes in this area which are hopefully helping you too. Adam -- Adam [email protected] Lackorzynski http://os.inf.tu-dresden.de/~adam/