Il 17/06/2013 17:28, Stefan Hajnoczi ha scritto: >> > + qemu_mutex_lock(&ctx->bh_lock); >> > bh->next = ctx->first_bh; >> > + /* Make sure the memebers ready before putting bh into list */ > s/memebers/members/ > >> > + smp_wmb(); > Why lock bh_lock before assigning bh->next? Could you lock the mutex > here and then drop the smp_wmb() since the pthread function already does > that? > > http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_11
Not sure I understand, ctx->first_bh is read here and that's what the lock protects. thread 1 thread 2 ------------------------------------------------------------------ bh->next = ctx->first_bh; bh->next = ctx->first_bh; lock ctx->first_bh = bh; unlock lock ctx->first_bh = bh; unlock and thread 2's bottom half is gone. There is also a similar race that leaves a dangling pointer if aio_bh_new races against aio_bh_poll. Paolo