All of lore.kernel.org
 help / color / mirror / Atom feed
* [KJ] question about race condition
@ 2007-01-18 19:27 Shaobo Liu
  2007-01-18 20:07 ` Jaco Kroon
  2007-01-18 20:16 ` Alexey Dobriyan
  0 siblings, 2 replies; 3+ messages in thread
From: Shaobo Liu @ 2007-01-18 19:27 UTC (permalink / raw)
  To: kernel-janitors


[-- Attachment #1.1: Type: text/plain, Size: 1109 bytes --]

I have a question about concurrence confusing me a lot.
 
As we know, when a resource is shared by multiple processes, we need some
mechanism to protect 
shared resource. 
For example, process A and process B both share a data structure DS.
Both A and B want write new data into DS. 
 
Usually we use a mutex to protect DS, 
here the mutex is defined as:
        
DECLARE_MUTEX(mut);
 
for process A
{
 
.....
down_interruptible(&mut);
A operates on DS;
up(&mut);
 
.......
}
 
 
for process B
{
 
.....
down_interruptible(&mut);
B operates on DS;
up(&mut);
 
.......
}
 
If the above pseudo code is run on a multi-core system, and if one core
tries "down_interruptible(&mut) " 
in process A,  with  another core trying "down_interruptible(&mut);" in
process B exactly at the same time, both A and B
will get the semaphore simultaneously, and then operate on DS.
 
It seems we have no way to protect the shared resource at all.
The similar logics also fit in with other locking mechanism such as mutex,
spinlock, and atomic variables.
 
Can you tell me my misunderstaning about above scenario.
 
Thanks. 

 


[-- Attachment #1.2: Type: text/html, Size: 7526 bytes --]

[-- Attachment #2: Type: text/plain, Size: 168 bytes --]

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-01-18 20:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-18 19:27 [KJ] question about race condition Shaobo Liu
2007-01-18 20:07 ` Jaco Kroon
2007-01-18 20:16 ` Alexey Dobriyan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.