fork and file descriptor
From: Jacky Cheung (jackylb_at_yahoo.com)
Date: 03/08/05
- Next message: Gianni Mariani: "Re: C++ Socket Libraries"
- Previous message: David Schwartz: "Re: How can I create a function with a shell variable name"
- Next in thread: David Schwartz: "Re: fork and file descriptor"
- Reply: David Schwartz: "Re: fork and file descriptor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 08 Mar 2005 11:39:54 +0800
Hi all,
My program has a main loop and a thread.
The main loop is used to fork a child and the thread is used write data
to dsp.
However I find that there is a cases when the thread opened the dsp, and
at that time the main loop fork a child out. This made the child has the
fd of dsp. So I am thinking to use mutex to make sure dsp is opened in
the child.
Here is my way:
Thread:
mutex lock
open dsp
write data to dsp
close dsp
mutex unlock
main loop:
mutex lock
if((child_pid=fork())<0){
DEBUG(0, "fork error \n");
}else if(child_pid==0){ //child
//do sth here
}else{ //parent
mutex unlock
}
Is it the right location to place the mutex unlock under the parent
process in the main loop? Also does the child need to hanlde the mutex lock?
Thx a lot.
Jacky
- Next message: Gianni Mariani: "Re: C++ Socket Libraries"
- Previous message: David Schwartz: "Re: How can I create a function with a shell variable name"
- Next in thread: David Schwartz: "Re: fork and file descriptor"
- Reply: David Schwartz: "Re: fork and file descriptor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|