Re: recursive spinlocks. Shoot.

Davide Libenzi (davidel@xmailserver.org)
Sun, 18 May 2003 16:26:26 -0700 (PDT)


On Mon, 19 May 2003, Peter T. Breuer wrote:

> No. This is not true. Imagine two threads, timed as follows ...
>
> .
> .
> .
> .
> if ((snl)->uniq == current) {
> atomic_inc(&(snl)->count); .
> } else { .
> spin_lock(&(snl)->lock); .
> atomic_inc(&(snl)->count); .
> (snl)->uniq = current; <-> if ((snl)->uniq == current) {
> atomic_inc(&(snl)->count);
> } else {
> spin_lock(&(snl)->lock);
> atomic_inc(&(snl)->count);
> (snl)->uniq = current;
>
>
> There you are. One hits the read exactly at the time the other does a
> write. Bang.

So, what's bang for you ? The second task (the one that reads "uniq")
will either see "uniq" as NULL or as (task1)->current. And it'll go
acquiring the lock, as expected. Check it again ...

- Davide

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/