EmbLogic's Blog

semophore doubt

In character driver ,we initialize the semaphore variable through sema_init(struct semaphore *sem,int val).so my question is how can we check semaphore variable value in our code and where this value get stored in struct semaphore…..

as we check the value through :
printk(KERN_INFO “semophore count= %d\n”,(int)&sculldev->sem.count);

but it shows the negative value….

Is there any other way to check the semophore variable…Please guide…

One Response to semophore doubt

  1. If you check the kernel Sources the semaphore structure contains only three members 1-Spinlock 2-unsigned int count 3-struct list_head *list_head;

    There is a comment above this structure that you cannot access the members of this structure directly .

    And the value u give as second argument of sema_init() is jst decide the maximum length of the list_head type link list . So the value (2nd argument of sema_init()) does not define the processes which can access the critical section . The value defines the maximum no. of processes that are maintained by that structure . It also includes the spinlock locking mechenism. And this is the main reason tht semaphore is a heavyweight synchronisation technique .

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>