On Wed, Jul 20, 2005 at 10:12:33AM +0530, ns srinivasa murthy wrote: > I could not find any difference between the functions set_bit and clear_bit. There is: set_bit() sets a bit, while clear_bit() clears a bit. > But it is mentioned in bitops.h file that smp_mb__before_clear_bit() > and/or smp_mb__after_clear_bit() shall be called in order to ensure changes > are visible on other processors.This is mentioned for bit_clear() function > only. clear_bit() uses a LOCK prefix, so the result will be atomic and visible to the other processors. However, the compiler can reorder the instruction of the function (it's an inline function), and that could lead to unwanted results if you use it to create locks. In order to force the compiler to issue the instruction on the place you want, you need to put a memory barrier before or after clear_bit(). > My doubt: > Is it not required to call smp_mb__before_set_bit() and > smp_mb__after_set_bit() in case of set_bit() function. > If not why is it not required? It is only required when you need set/clear_bit() for locking purposes, not when you just want to set or clear a bit. (don't see this as an invitation to invent your own locking primitives, use what the kernel already has available). Erik -- Erik Mouw J.A.K.Mouw@xxxxxxxxxxxxxx mouw@xxxxxxxxxxxx
Attachment:
signature.asc
Description: Digital signature