/* * Copyright (C) 2004 Aleksandar Colovic * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * */ #include #include #include #include #include #include #include using namespace std; int main (int argc, char* const argv[]) { int fd = open("/tmp/pmutex", O_RDWR); void* pMem = mmap (NULL, 4*1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); pthread_mutex_t* pMutex = (pthread_mutex_t*)pMem; cout << "Process 2 waiting for the mutex ..." << endl; pthread_mutex_lock (pMutex); cout << "Process 2 got the mutex ..." << endl; pthread_mutex_unlock(pMutex); cout << "Process 2 released mutex. Exiting ..." << endl; close(fd); return 0; }