I have this program in C++ that forks two new processes:
#include
#include
#include
#include
Does this apply to pthread_mutex objects also. Say I have mutex in the parent that gets locked and unlocked in a particular function. Now the parent creates a child process. Both parent and child can call this function simultaneously (Parent not really blocked till child exits as parent is a multi-threaded program, the thread that spawns child is only one blocked). So is the mutex object state - shared between the 2 processes? If in parent, mutex was locked then child was created child gets to run first child sees the mutex in locked state as it has just inherited the mutex object as it is from parent now child unlocks mutex How is the state of this mutex in parent now - still locked (because parent never unlocked) or Unlocked because child has unlocked it.
Is it ok to call such a function that locks/unlocks global mutexes from parent and child?