Operating System - HP-UX
1753366 Members
5449 Online
108792 Solutions
New Discussion юеВ

Re: MUTEX var management in fork/exec context

 
SOLVED
Go to solution
Fedele Giuseppe
Frequent Advisor

MUTEX var management in fork/exec context

Hello,

I'm using MUTEX varibales in a multithread context to protect data integrity.

In the same context I have to use fork/exec paradigm and the CHILD processes ARE NOT multithreading.

My question is: how the MUTEX variables are managed by the child process? It is needed to unlock them in the child code, before proceeding?

Thanks

Giuseppe

7 REPLIES 7
Dennis Handly
Acclaimed Contributor
Solution

Re: MUTEX var management in fork/exec context

>It is needed to unlock them in the child code, before proceeding?

You need to set up pthread_atfork(3) handlers that unlocks each mutex.
Fedele Giuseppe
Frequent Advisor

Re: MUTEX var management in fork/exec context

Another question: how to manage signals in fork/exec context?

It is needed to reset signals handling mechanism in the child process?

James R. Ferguson
Acclaimed Contributor

Re: MUTEX var management in fork/exec context

Hi Giuseppe:

> Another question: how to manage signals in fork/exec context?

The manpages for 'fork()' note:

"The child process inherits the following attributes from the parent process:
...
Signal handling settings (SIG_DFL, SIG_IGN, address).

...[BUT]...

The child process differs from the parent process in the following ways:
The set of signals pending for the child process is initialized to the empty set."

Regards!

...JRF...
Fedele Giuseppe
Frequent Advisor

Re: MUTEX var management in fork/exec context

Hi James,

if I have well understood, the child inherits all signals handling settings.

But it is not clear for me the meaning of the sentence:
"The set of signals pending for the child process"

Many thanks

Giuseppe
James R. Ferguson
Acclaimed Contributor

Re: MUTEX var management in fork/exec context

Hi (again) Giuseppe:

> But it is not clear for me the meaning of the sentence: "The set of signals pending for the child process is initialized to the empty set."

I read this to say that any signals that were pending (delivery) because they were blocked by your code would simply be discarded so that the child process created by the fork() would be devoid of un-delivered signals.

Regards!

...JRF...
Fedele Giuseppe
Frequent Advisor

Re: MUTEX var management in fork/exec context

Ok,

so, no actions for signal handling are needed in child process code, right?

Giuseppe
Dennis Handly
Acclaimed Contributor

Re: MUTEX var management in fork/exec context

>no actions for signal handling are needed in child process code, right?

If you are going to exec, you need to rearm the signal handlers.