Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7744523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:47:17+00:00 2026-06-01T09:47:17+00:00

I am trying to implement Mutex lock on one of my static function of

  • 0

I am trying to implement Mutex lock on one of my static function of single ton class. But getting this error:

$error:‘m_Mutex’ declared as reference but not initialized
$warning:warning: unused variable ‘m_Mutex’

Here is my code snippet.

========Commondefines.h==========

/**
*@class LockBlock
*This class is used to provide Mutex Lock on thread.
*/
class LockBlock
{
    public:
        LockBlock(pthread_mutex_t *mutex)
        {
            lockMutex = mutex;
            pthread_mutex_lock(lockMutex);
        };


        ~LockBlock()
        {
            pthread_mutex_unlock(lockMutex);
            lockMutex = NULL;
        }


    private:
        pthread_mutex_t *lockMutex;
};

========MutexImplenation.h======

#include "CommonDefines.h"

class MutexImplementation
{

  private:
     static pthread_mutex_t m_Mutex ;

  public:
     static void commonFunction();

};

====MutexImplementation.cpp==========

// Initialize static member of class.
pthread_mutex_t MutexImplentation::m_Mutex = PTHREAD_MUTEX_INITIALIZER;


void commonFunction()
{
   LockBlock(&m_Mutex); // Here I am getting this error.


}

Any help would be highly appreciated.
Thanks,
Yuvi

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:47:18+00:00Added an answer on June 1, 2026 at 9:47 am

    This is really a variant of the “most embarassing parse” problem.
    You’ve not defined a m_Mutex anywhere except as a member of
    MutexImplementation, so outside of MutexImplementation, its name is
    MutexImplementation::m_Mutex (and since it’s private, you can’t
    legally access it). When you write:

    LockBlock (&m_Mutex);
    

    , the compiler cannot find m_Mutex, and so supposes that you are
    defining a local variable. The parentheses are legal, but have no
    effect, and the declaration is the same as:

    LockBlock& m_Mutex;
    

    A reference to LockBlock, and references can only be defined if they
    are initialized.

    If you want a local variable, you’ll have to give it a name. And if you
    want it initialized to m_Mutex, you’ll have to make m_Mutex public,
    and specify the class name as well:

    LockBlock& localRefToMutex( &MutexImplementation::m_Mutex );
    

    for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to implement read/write lock using mutex only (just for learning). Just
I am trying to use boost::shared_mutex to implement a multiple-reader / single-writer mutex. My
Trying to implement the new FP 10.1 Global error handler into my projects but
I'm trying to implement single instance application using mutex. the application can run only
im trying to implement a custom error page, what i want to be able
Ok well I'm trying implement something similar to the 'undo' function in many image
Trying to implement simple error handling without adding buku try / except statements to
I don't know what this is called but here goes. public class Person {
SetFocus I'm trying implement the above Se Focus code in a Class Library that
Trying to implement this gallery on my website. http://coffeescripter.com/code/ad-gallery/ It is noted in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.