Re: do nothing loop

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

 



On Wed, Dec 19, 2001 at 12:50:57AM -0500, D Cleveland wrote:
> int p=0;
> while(!p);
> 
> so have the code do nothing until the variable p is equal to 1.  Is a
> while loop the best or is there a nicer method?

Dan, it depends upon how long you intend to be looping. If it will be
for short-times only, you can use the atomic_t variables (which do
mostly this, but with 'volatile int p' to force memory access, rather
than allow compiler optimizations to wreck your day :), or spinlocks
(which probably just package that up nicely).

If you might need to be in this loop for a while, use semaphores
instead. One can sleep while holding semaphores.

Take a look into Documentation/*lock*txt (sorry I forget the exact name :)
for more details.

Cheers!

-- 
The Bill of Rights: 7 out of 10 rights haven't been sold yet! Contact
your congressman for details how *you* can buy one today!

PGP signature


[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