On Tue, May 8, 2012 at 10:41 PM, Christoph Hellwig <[email protected]> wrote: > On Tue, May 08, 2012 at 08:40:34PM +0800, Yunkai Zhang wrote: >> > ? ? ? ?if (!uatomic_read(&zk_notify_blocked) && >> > ? ? ? ? ? ? uatomic_read(&nr_zk_levents)) { >> > ? ? ? ? ? ? ? ?nr_levents = uatomic_sub_return(&nr_zk_levents, 1) + 1; >> > >> > I guess he means the possible race between uatomic_read() and >> > uatomic_sub_return() on the same value. >> >> I have explained - when we are trying to subtract nr_zk_levents, it >> will be added by watcher() in another thread. > > I still don't really understand the problem. If we need this to be > atomic (and I think we do) we'd need something like > atomic_dec_if_positive in the Linux Kernel - unfortunately urcu does not > seem to provide an equivalent.
Yes, if gcc supports atomic_dec_if_positive(), I like to use it, but it doesn't. It works well now, I don't know what you worry about? > > Normally you'd use a proper lock for this sort of concurrency issue, > if you need something lockless you'd want a relatively complicated > producer/consumer queue like the one in include/linux/llist.h in the > Linux Kernel. -- Yunkai Zhang Work at Taobao -- sheepdog mailing list [email protected] http://lists.wpkg.org/mailman/listinfo/sheepdog
