#include <iostream>
#include <sched.h>
#include <time.h>
#include <pthread.h>
#include <string>
#include "sem.h"
using namespace std ;
/* "Checking" is just a flag that you set to 1 if you want lots of
debugging messages and set to 0 otherwise. The semaphore code in
sem.cpp imports "checking". Therefore the semaphore operations
will write lots of messages if you set checking=1. */
int checking ;
/* Use this flag to turn on checking in your main program file. */
int my_checking ;
/* In some programs, we use the "stdoutLock" variable declared below to
get intelligible printouts from multiple concurrent threads that
write to the standard output. (There has to be something to prevent
the output of the threads from interleaving unintelligibly on the
standard output, and we can't use semaphores if the semaphore code is
writing messages too.)
To print a message to standard output, a thread first locks standard
output, then writes, then unlocks standard output. See files sem.cpp
or conc.cpp for examples of code that write messages in this manner.
WARNING: DON'T change how the locking of standard output is done
until you've thought a WHOLE lot about the consequences. In
particular, using semaphores to do the job of stdoutLock can cause
"infinite recursion" under certain circumstances. The reason is that
the semaphore code itself imports "stdoutLock" and writes messages
when the "checking" variable is set to 1. */
pthread_mutex_t stdoutLock ;