Re: Help with char device

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

 



On Sat, Jul 27, 2002 at 04:52:00PM -0300, Rik van Riel wrote:
> On Sat, 27 Jul 2002, Tom Bradley wrote:
> > ssize_t my_read(struct file * filp, char * buf, size_t count, loff_t * fpos)
> > {
> >
> > 	ssize_t ret;
> > 	struct semaphore sem;
> 
> Note that I'm not familiar with the semaphore code, so I could be
> wrong ... but won't this effectively give each thread going into
> this code its OWN semaphore on its own stack ?
> 
> If it does so, the semaphore won't take care of mutual exclusion
> between threads.

Sure that gives each thread a it's own semaphore on it's own stack.
Semaphores must be either static or global to work. In addition, they
have to be initialized (that's what gave the segfault). Since the
semaphore is not a structure member, easiest way is to delare it using
the DECLARE_MUTEX or __DECLARE_SEMAPHORE_GENERIC macro.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
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