This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: kernel-2.2.1-undefined references.
At 10:12 PM 2/14/99 -0500, you wrote:
>I don't think so. How the hell else can you write C code that works with
>data that changes asynchronously, e.g. because of multiple threads or
>because of hardware or interrupts or signal handlers or...
By the way, don't say use mutexes and semaphores.
1. Hardware doesn't understand these things, and you do need software
to interface to hardware.
2. A modal signal/exception handler would be in deep trouble if it
encountered a mutex that was locked and decided to wait for it to
unlock...and wait, and wait, and wait...
3. The semaphores and mutexes need to be coded as well. They need
state variables, and those state variables need to be modified
asynchronously, *without* using a mutex or semaphore as this would
be a chicken and egg problem! So the mutex flag or semaphore
counter needs to be 'volatile', so code like this:
void mutex::get_lock (void) throw () {
suspend_task_switching();
while (locked) {
resume_task_switching();
yield();
suspend_task_switching();
}
locked=true;
resume_task_switching();
}
doesn't hang in an infinite loop because 'locked' was optimized
into a register and the while loop therefore never exits since its
register copy of 'locked' never changes! So we need
private:
volatile bool locked;
or the mutex class won't work worth a damn.
--
.*. "Clouds are not spheres, mountains are not cones, coastlines are not
-() < circles, and bark is not smooth, nor does lightning travel in a
`*' straight line." -------------------------------------------------
-- B. Mandelbrot |http://surf.to/pgd.net
_____________________ ____|________ Paul Derbyshire pderbysh@usa.net
Programmer & Humanist|ICQ: 10423848|