semaphore question



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

.



Relevant Pages

  • semaphore question
    ... Below is a simple pseudocode using semaphore: ... If one process is executing ... LINE1 or LINE2, no other processes can enter the critical section. ...
    (comp.os.linux.development.apps)
  • Question about semaphore
    ... Below is a simple pseudocode using semaphore: ... If one process is executing ... LINE1 or LINE2, no other processes can enter the critical section. ...
    (comp.unix.programmer)
  • Re: Question about semaphore
    ... If one process is executing ... LINE1 or LINE2, no other processes can enter the critical section. ... mutex protocol. ...
    (comp.unix.programmer)
  • Re: semaphore question
    ... LINE1 or LINE2, no other processes can enter the critical section. ... can mutex2 control the execution of LINE1 and LINE2? ... I am trying to understand semaphore. ...
    (comp.os.linux.development.apps)
  • RE: [opensuse] How to insert lines into text file ?

    (SuSE)