Mutex locker class in C++ What needs to be corrected, added, or subtracted here?

class mutexLocker
{
    private:
    /* Declaration of a Mutex variable `mutexA`. */
    pthread_mutex_t &amp;mutexA;

    /* `mutexStatus` holds the return value of the function`pthread_mutex_lock `. 
    This value has to be returned to the callee so we need to preserve it in a class
    variable. */
    int             mutexStatus;

    public:
    /* Constructor attempts to lock the desired mutex variable. */
    mutexLocker (pthread_mutex_t argMutexVariable) 
    : mutexA (argMutexVariable)
    {
        /* Return value is needed in order to know whether the mutex has been 
        successfully locked or not. */
        int mutexStatus = pthread_mutex_lock (&amp;argMutexVariable);
    }

    /* Since the constructor can't return anything, we need to have a separate function
    which returns the status of the lock. */
    int getMutexLockStatus ()
    {
        return mutexStatus;
    }

    /* We may need this Mutex variable as an argument for `pthread_cond_wait()`*/
    pthread_mutex_t getLockedMutex ()
    {
        if (mutexStatus &gt;= 0)
            return mutexA;
    }

    /* The destructor will get called automatically whereever the callee's scope ends, and
    will get the mutex unlocked. */
    ~mutexLocker ()
    {
        if (mutexStatus &gt;= 0)  
             pthread_mutex_unlock (&amp;mutexA);
    }
};
If you are keeping a reference to an object you should pass that object to the constructor as a reference:

mutexLocker (pthread_mutex_t    argMutexVariable) 
                    //     ^^^  Missing reference.


You return the state of the lock operation:

int getMutexLockStatus ()


But if the mutext failed to lock what are you going to do.
If the mutext fails to lock there is probably something fundamentally wrong so you should probably stop the current action by throwing an exception.

You can't conditionally return a value.
You must always return something from a function that expects to return value.

pthread_mutex_t getLockedMutex ()
{
    if (mutexStatus &gt;= 0)
        return mutexA;


    // What happens if the code gets here?
    // Letting a function return without an explicit return (in a non void method)
    // is undefined behavior.
}


Also I see no point in testing the status.
If the lock failed to lock you should have exited the code much earlier than this. If the lock fails throw an exception.

Your test is also incorrect (here and the destructor)

if (mutexStatus &gt;= 0)  


If the mutex did lock then it returned 0 and thus the mutexStatus is zero.