lkml.org 
[lkml]   [1996]   [Nov]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectBehavior of semaphore's down/up functions (2.0.24)

Hi, any experts there willing to help:

I am a new grad learning to write linux device drivers and want to
understand some kernel codes related to driver programming.

I have a question on the behavior of semaphore's down/up functions..... :

-----------------------------------------------------------------------
Running several processes with the same testing program which calls this
piece of code inside driver:

static struct semaphore sem = MUTEX/*global variable initialized as {1,0,NULL}*/
...
/* printk indicating that down is about to called with the preocess identifier
(local variable copied from user space varible, the address of which
is passed as one argument of ioctl() ). */
down(&sem);
/* printk indicating this process coming out of down and holding the device.
/* sleep for a while */
up(&sem);
/* printk indicating up is called */
scheduler();
...

giving the result in /var/adm/syslog:

process 0 down
process 0 got device
process 1 down
process 0 up
process 0 down
process 0 got device

while what is expected on the last line is "precess 1 got device" because
precess 1 did the down before process 0 did it the second time.

Thanks in advance.

Best regards.

Bo


\
 
 \ /
  Last update: 2005-03-22 13:38    [W:0.162 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site