Return to Implementing Threads
From: Evan Jones <ejones@uwaterloo.ca> Date: Mon Oct 21, 2002 17:56:02 Europe/Zurich To: [...] Subject: Re: About locking in multi-threaded environments On Sunday, Oct 20, 2002, at 10:18 Europe/Zurich, [...] wrote: > I've just come along with > "Implementing a Thread Library on Linux", > and I want you to reconsider your text about no need to use > locking when using a user level thread model/library on > a single processor. Although you alert of the consecuences of > such 'technique', I am strongly against such idea because it is > simply bad style, error-prone programming. This is very true: Threading is a complicated and frequently error prone programming task. From a strictly "academic" discussion about threading, what I have said is technically true: There is no REAL concurrency, and there is also no REAL pre-emption. This means that locking is not necessary to avoid conflicts when using shared resources, because as a programmer you have explicit control over when threads execute and when control switches between threads. However, you are absolutely correct: If you do not take care when adding thread_yield() calls, you can write software that will malfunction. However, if you are not careful with calls to lock and unlock the semaphores or whatever locking primitive you are using, similar problems can arise. Still, I will add a note to that paragraph of my document to attempt to make my statements more clear. Let me know if you have any further questions or comments, Evan