Date: Tue, 20 Oct 98 08:01:12 -0500 From: "Richard Seaman, Jr." <lists@tar.com> To: "HighWind Software Information" <info@highwind.com> Cc: "current@freebsd.org" <current@FreeBSD.ORG> Subject: Re: Another Serious libc_r problem Message-ID: <199810201301.IAA09236@ns.tar.com>
next in thread | raw e-mail | index | archive | help
On Mon, 19 Oct 1998 16:45:32 -0400 (EDT), HighWind Software Information wrote: >Simply to placate your claim, here is another version that locks and >unlocks the mutex in proper fashion. I simply had to insert an >additional "sleep" to get the bug to appear. > >In both cases, spinning the CPU at 100% and allowing the program to >hang and make no forward progress is a SERIOUS bug. > >I claim that this new version is 100% valid. Does proper locking, and >also works on other O/S's. On FreeBSD it does not work at all. > >-Rob I can confirm that your test program behaves as you describe on my machine also. I haven't had a lot of time to look at it, but I'd *guess* that what happens is this: 1) The main thread starts its loop by locking the mutex 2) It calls pthread_cond_signal, which in turn wakes up one of your sleeping condThreads. 3) Upon waking up inside pthread_cond_wait, the condThread locks the spinlock for the cond variable condition (this is the error which leads to the deadlock) 4) the condThread tries to lock the mutex, finds it locked already, so it waits (still inside pthreat_cond_wait) 5) meanwhile, the main thread enters pthread_cond_signal a second time, and tries to lock the spinlock for condition. Its already locked by a condThread, so it waits. 6) result: deadlock The fix is to clean up the spinlock code in the pthread_cond_* code. As far as I can tell, the spinlock on the condition variable should only be set when the condition variable structures are being messed with. If this is do, and the code fixed appropriately, my guess is that the deadlock would be eliminated. I will try to look at this later, if I have time. However, there are others who know a lot more about this than I do who could probably do a better fix. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810201301.IAA09236>
