"David S. Miller" wrote:
> It is very common to do things like:
> elem->next = list->head;
> xchg(&list->head, elem);
> local_list = xchg(&list->head, NULL);
> for_each(elem, local_list)
producer() looks broken. The problem is two producers can race and
one will put the wrong value of list->head in elem->next.
I think prepending to list->head needs to either be protected by a spinlock
or be a per-cpu data structure. consumer() should be ok assuming the code
can tolerate picking up "late arrivals" in the next pass.
Or am I missing something obvious here?
It's worse if producer were inlined: the arch specific optimisers might
re-order the "elem->next = list->head" statement to be quite a bit more
than 1 or 2 cycles from the xchg() operation.
Unix Systems Enablement Lab
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to firstname.lastname@example.org
Please read the FAQ at http://www.tux.org/lkml/