circ buffer & locking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
when I have a circular buffer like:
struct circular_buf {
	char buf[];
	volatile int head, tail;
};

And I have one producer and one consumer.
The producer modifies the head and reads tail.
The consumer modifies the tail and reads head.
Producer and consumer are executed in different threads.
Is it sufficient to qualify head and tail with volatile or is some
kind of locking needed?
(When I transfer this example to user space and pthreads
proper locking is needed (mem sync) -- in this domain volatile is despised.
How is this with the kernel?)

/FAU
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux