Re: Thread safe circular buffer.

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

 



Tzahi Fadida wrote:

> Hi,
> I am reading ldd3 and i am trying to understand how a circular buffer without 
> locking works. 
> If there is one writer and multiple readers. The writer has a pointer to head. 
> the readers each have a pointer of their own to tail. Assumming the head 
> can't circle on the tail in time, everything is peachy.
> However, in ldd3 the readers are sharing the tail pointer, how can this be 
> alright? (See the code in ldd3->interrupt handling->Implementing a handler)
> At the very least you should somehow atomically grab the tail into a local var 
> and also atomically increase the tail position all in one go so you won't get 
> a race condition.
>   
Hello Tzahi,
this code is just a sample of who interrupt handlers works,
it doesn't guarantee anything about concurrency.

Moreover, if you download the code example files from Oreilly,
on this specific example you refer above, you can read on first lines:

/*
 * FIXME: this driver is not safe with concurrent readers or
 * writers.
 */

There are lot of lock-free or wait-free algorithms for data structures,
you can find them easily on google,
from LDD you can only learn how to program
a device driver, not how to make it efficient.

Thanks,
    Stavros Passas

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at 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