Re: preemptive kernel

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

 



kkonaka@mac.com <kkonaka@mac.com> [2003-09-12 00:03]:

> int busy = 0;
> wait_queue_head_t q;
> some_resource res; /* data structure shared between processes */
> 
> ssize_t my_write(struct file * file, const char * buf,
>                        size_t count, loff_t *ppos)
> {
>     while (busy) {    /* grab exclusive access */
>       interruptible_sleep_on(&q);  
>     }
> 
>     <do something assuming exclusive access to resources>
> 
>     busy = 0;        /* release exclusive access */
>     wake_up_interruptible(&q);
>     return retval;
> }
> 

Is this code supposed to be race-condition-free and to be working on
multiprocessing environments?  If so, you should consider using atomic
instructions like mutexes and semaphores....

wbr,
Lukas
-- 
Lukas Ruf           | Wanna know anything about raw |
<http://www.lpr.ch> | IP?  <http://www.rawip.org>   |
--
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