27 #include <utils/ipc/semset.h> 30 #include <sys/types.h> 43 signal_handler(
int signum)
45 cout <<
"Signal handler called" << endl;
50 main(
int argc,
char **argv )
53 signal(SIGINT, signal_handler);
57 if ((child_pid = fork()) == 0) {
62 while ( !s2->
valid() ) {
70 cout <<
"Child: Unlocking child lock" << endl;
73 cout <<
"Child: Waiting for father lock to become ready" << endl;
74 s2->
lock(FATHER_LOCK);
75 cout <<
"Child: Father lock aquired, unlocking" << endl;
78 cout <<
"Child: Sleeping" << endl;
80 cout <<
"Child: Locking child lock" << endl;
82 cout <<
"Child: Sleeping again" << endl;
86 cout <<
"Child: Destroying s2" << endl;
97 cout <<
"Father: Unlocking father lock" << endl;
100 cout <<
"Father: Waiting for child lock to become ready" << endl;
101 s1->
lock(CHILD_LOCK);
102 cout <<
"Father: Child lock aquired, unlocking" << endl;
105 cout <<
"Father: Sleeping" << endl;
107 cout <<
"Father: Locking father lock" << endl;
108 s1->
lock(FATHER_LOCK);
109 cout <<
"Father: again" << endl;
113 cout <<
"Father: Waiting for child to exit" << endl;
115 waitpid(child_pid, &status, 0);
117 cout <<
"Father: Destroying s1" << endl;
bool valid()
Check if the semaphore set is valid.
Fawkes library namespace.
void lock(unsigned short sem_num=0, short num=1)
Lock resources on the semaphore set.
void unlock(unsigned short sem_num=0, short num=-1)
Unlock resources on the semaphore set.