Re: locking question in the SMP era

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

 



Hi,

First of all: please *do* reply *after* the message. Top-posting sucks
(http://en.wikipedia.org/wiki/Top-posting).

Roy Smith wrote:

> I'm mostly concerned about a module which export a read/write proc entity to 
> user world, but would be most thankful for a general answer.

A general answer is not really possible, or at least won't help you much.

Here can be one : « All data accessed concurrently by different threads
has to be protected against concurrent accesses ». In kernel space, to
do so, you can use:
 - atomic operations ;
 - spinlocks ;
 - semaphores ;
 - ?

> how should I lock the proc from user access ?

You don't need to "lock the proc from user access", you need to protect
the data accessed concurrently by different threads.

> and more generally: If i can be invoked concurrently on several processors, 
> should I lock every variable from myself, too ?

The concurrent access problem doesn't occur only on multi-processor
systems: it can also occur on uni-processor systems, because of the
preemptive scheduling.

You don't need to lock "every variable" again, you need to protect the
data accessed concurrently by different threads. For example, you don't
need to protect local variables (allocated on the stack), but if you
have a global array, a global linked list or a global integer, you need
to protect it against concurrent accesses.

As you don't seem to know well the problem of synchronization, I suggest
you to read the first chapter of
http://greenteapress.com/semaphores/downey05semaphores.pdf. Of course,
the other chapters are also of interest, but the first one is a
presentation of the mutual exclusion problem, etc.

Sincerly,

Thomas
-- 
Thomas Petazzoni
thomas.petazzoni@xxxxxxxx


--
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