Comparison of PTHREAD_PROCESS_SHARED in Soaris and FreeBSD
Let us begin with the sample code below (headers omitted for brevity): int main(int argc, const char* argv[]) { void* mmap_ptr = mmap (NULL, sizeof (pthread_mutex_t), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0); if (mmap_ptr == MAP_FAILED) { perror ("mmap failed"); return -1; } fprintf (stderr, "mmaped at: %x\n", mmap_ptr); pthread_mutex_t* mutp = (pthread_mutex_t*)mmap_ptr; // initialize the attribute pthread_mutexattr_t attr; pthread_mutexattr_init (&attr); pthread_mutexattr_setpshared (&attr, PTHREAD_PROCESS_SHARED); // this is what we're testing // initialize the mutex pthread_mutex_init (mutp, &attr); pthread_mutexattr_destroy (&attr); // acquire the lock before fork pthread_mutex_lock (mutp); pid_t chld = fork (); if (chld != 0) { // parent fprintf (stderr, "parent: going to sleep...\n"); sleep (30); fprintf (stderr, "parent: unlocking.\n"); pthread_mutex_unlock (mutp); } else { /...