Re: Definition of spin_lock(lock) and spin_unlock(lock)

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

 




Semaphores are used for synchronization.   If you have a piece of code,
which will be run by multiple threads,
then semaphores is one way of synchronization.  The condition to enter the
code could be when the semaphore
value is 0.  The thread would then make it 1 atomically thus obtaining the
lock and at the end would make it 0 again.
 Any other thread will not be able to execute the code till the semaphore
value becomes 0.

Other ways of synchronization are to use mutex, which are implemented using
pthreads.

Hope this helps.
Cheers,
Sharath



                                                                                                                
                      Halil Demirezen                                                                           
                      <demirh@bilmuh.ege.edu        To:       kernelnewbies@nl.linux.org                        
                      .tr>                          cc:                                                         
                      Sent by:                      Subject:  Definition of spin_lock(lock) and                 
                      kernelnewbies-bounce@n         spin_unlock(lock)                                          
                      l.linux.org                                                                               
                                                                                                                
                                                                                                                
                      05/30/2002 12:54 AM                                                                       
                      Please respond to                                                                         
                      Halil Demirezen                                                                           
                                                                                                                
                                                                                                                




in linux/spinlock.h the spinlocks are defined
and i want to know what kind of a reasonability does it have to define
spin_lock and spin_unlock in the following way.


#define spin_lock(lock) do {} while(0)
#define spin_unlock(lock) (void)...


to be shorty, what is the actual aim of spin_lock and spin_unlock ,
spin_lock_irq spin_unlock_irq.....etc

and what is the aim of semaphores.

i have read a documentation that basically describes them but not in more
detail so that i counld not get it well enough.

sincerely.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/





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