semaphore question
- From: "Jack" <junw2000@xxxxxxxxx>
- Date: 14 Aug 2006 12:06:45 -0700
Below is a simple pseudocode using semaphore:
while(1){
wait(mutex1); //LINE0
open(file_f); //LINE1
write(file_f); //LINE2
signal(mutex1);
}
Here, LINE1 and LINE2 are critical section. If one process is executing
LINE1 or LINE2, no other processes can enter the critical section. Can
other processes or users access the file file_f, such as delete of
change it?
My understanding is that the critical section is only LINE1 and LINE2,
not the file_f, so the semaphore can only control the access of the
LINE1 and LINE2, not the file file_f.
Another situation is that if another user A of the same machine write
another piece of code (different code from the above code) to access
file_f as below:
while(1){
wait(mutex2);
open(file_f); //LINE3
write(file_f); //LINE4
signal(mutex2);
}
Can mutex1 at LINE0 prevents user A from executing LINE3 and LINE4? Or
can mutex2 control the execution of LINE1 and LINE2?
Thanks a lot.
Jack
.
- Follow-Ups:
- Re: semaphore question
- From: 42Bastian Schick
- Re: semaphore question
- Prev by Date: how to implement ext2/ext3 filesytem in linux
- Next by Date: Re: HowTo check whether PAE is enabled on IA32?
- Previous by thread: how to implement ext2/ext3 filesytem in linux
- Next by thread: Re: semaphore question
- Index(es):
Relevant Pages
|