bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] Implementing a simple mutex using simple locks and futex calls


From: Richard Braun
Subject: Re: [RFC] Implementing a simple mutex using simple locks and futex calls
Date: Wed, 25 Sep 2013 13:53:38 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Mon, Sep 23, 2013 at 09:13:25AM +0200, Marin Ramesa wrote:
> int atomic_inc(mutex_t mtx)
> {
>       int ret = mtx->value;
>       
>       simple_lock(&(mtx->inc_lock);
>       mtx->value++;
>       simple_unlock(&(mtx->inc_lock));
> 
>       return ret;
> }

Besides, you fetch the value of the mutex outside the critical section.
This really is a beginner mistake, showing that you probably need to
gain experience with concurrency itself first.

-- 
Richard Braun



reply via email to

[Prev in Thread] Current Thread [Next in Thread]