Vehicle-crossing simulation It seems like this code should be shorter, but with all the error checking it is long and hard to follow. This is for a simulation of vehicles crossing a bridge, and this part is dealing with mutexes. I tried extracting a function that is passed the mutex and locks/unlocks it and prints any errors, but when I did that it broke the code (it's been my experience on this site to not include any broken code so I won't elaborate on what I tried).

/*global variables*/
pthread_mutex_t Bridge = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t okToOutput = PTHREAD_MUTEX_INITIALIZER;
/*...*/
/*this is the function that gets passed to pthread_create()*/
void* startSim(void *arg)
{

    Vehichle* inData = (Vehichle*)arg;
    if(usleep(inData-&gt;sleepT1))
        cerr &lt;&lt; "Vehichle " &lt;&lt; inData-&gt;licencePlate &lt;&lt; " failed to sleep" &lt;&lt; endl;
    if(pthread_mutex_lock(&amp;okToOutput))
        cerr &lt;&lt; "failed to lock output" &lt;&lt; endl;
    cout &lt;&lt; "Vehichle " &lt;&lt; inData-&gt;licencePlate &lt;&lt; " is ready to go " &lt;&lt; dirToStr(inData-&gt;direction) &lt;&lt; endl;       
    if(pthread_mutex_unlock(&amp;okToOutput))
        cerr &lt;&lt; "failed to unlock output" &lt;&lt; endl;

    if(pthread_mutex_lock(&amp;Bridge))
        cerr &lt;&lt; "failed to lock bridge" &lt;&lt; endl;
    if(pthread_mutex_lock(&amp;okToOutput))
        cerr &lt;&lt; "failed to lock output" &lt;&lt; endl;
    cout &lt;&lt; "Vehichle " &lt;&lt; inData-&gt;licencePlate &lt;&lt; " is ON the main bridge going " &lt;&lt; dirToStr(inData-&gt;direction) &lt;&lt; endl;
    if(pthread_mutex_unlock(&amp;okToOutput))
        cerr &lt;&lt; "failed to unlock output" &lt;&lt; endl;
    if(usleep(inData-&gt;sleepT2))
        cerr &lt;&lt; "Vehichle " &lt;&lt; inData-&gt;licencePlate &lt;&lt; " failed to sleep" &lt;&lt; endl;
    if(pthread_mutex_lock(&amp;okToOutput))
        cerr &lt;&lt; "failed to lock output" &lt;&lt; endl;
    cout &lt;&lt; "Vehichle " &lt;&lt; inData-&gt;licencePlate &lt;&lt; " is OFF the main bridge after going " &lt;&lt; dirToStr(inData-&gt;direction) &lt;&lt; endl;
    if(pthread_mutex_unlock(&amp;okToOutput))
        cerr &lt;&lt; "failed to unlock output" &lt;&lt; endl;
    if(pthread_mutex_unlock(&amp;Bridge))
        cerr &lt;&lt; "failed to lock bridge" &lt;&lt; endl;

    return NULL;
}


My compiler doesn't properly support C++11 so no smart pointers etc.
As mentioned in the comments, there's not much to review.

Don't abuse using namespace std

Putting using namespace std within your program is generally a bad habit that you'd do well to avoid.  

Factor out common code

In this case, the code gets a lock, does something, and releases the lock.  That could easily be isolated to a common function:

class Locker
{
     pthread_mutex_t&amp;   mutex;
     bool               ok;
   public:
     operator bool() const {return ok;}

     Locker(pthread_mutex_t&amp; mutex)
         : mutex(mutex)
         , ok(true)
     {
         if(pthread_mutex_lock(&amp;mutex) != 0) {
             cerr &lt;&lt; "failed to lock output" &lt;&lt; endl;
             ok = false;
         }
     }
     ~Locker()
     {
         if (ok) {
             if(pthread_mutex_unlock(&amp;mutex) != 0) {
                 cerr &lt;&lt; "failed to unlock output" &lt;&lt; endl;
             }
         }
     }
};          
void report(Vehicle *v, const char *msg)
{
    Locker    lock(okToOutput);
    if (lock) {
        cout &lt;&lt; "Vehicle " &lt;&lt; v-&gt;licencePlate &lt;&lt; msg &lt;&lt; dirToStr(v-&gt;direction) &lt;&lt; endl;       
    }
}


To do this correctly, a failure to lock should exit the routine and not attempt to send output data.

Avoid C-style casts

Instead of (Vehicle *)arg use static_cast&lt;Vehicle *&gt;(arg).  It makes much more clear to humans reading your code what you're doing.