Hi,
In a kernel module I have a variable A,
which is shared between processes and used
as a counter to protect access to other
variables, such as B.
IMO, Make your A a spinlock.
All accesses to A are properly
synchronized with spin_lock_irqsave and
spin_unlock_irqrestore, for example:
spin_lock_irqsave
if(A > 0)
{
update B;
A--;
}
spin_unlock_irqrestore
But in one place I also need to wait for A
to reach value 0 before reading B.
I was advised to use wait_event:
wait_event(wait_queue, A == 0);
Read and use B;
But I see that wait_event(wq, condition) is defined
as:
do {
if (condition)
break;
__wait_event(wq, condition);
} while (0)
Now I started to worry because I see that
wait_event executes (A == 0) comparison without
any protection by lock and without any barrier.
So, I imagine that on SMP system with relaxed
operation ordering the following may happen:
CPU 1 CPU 2
LOAD B
STORE B
STORE A = 0
LOAD A->0
Then CPU 2 will call wait_event, find that A == 0
and proceed using the old value of B.
So, my question is whether my analysis is correct
and what is the right way to use wait_event
in this situation?
Thank you
John
____________________________________________________________________________________
Don't get soaked. Take a quick peek at the forecast
with the Yahoo! Search weather shortcut.
http://tools.search.yahoo.com/shortcuts/#loc_weather
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ