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

  • Home
  • SEARCH
  • 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 5839545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:35:57+00:00 2026-05-22T11:35:57+00:00

Do all mutex implementations ultimately call the same basic system/hardware calls – meaning that

  • 0

Do all mutex implementations ultimately call the same basic system/hardware calls – meaning that they can be interchanged?

Specifically, if I’m using __gnu_parallel algorithms (that uses openmp) and I want to make the classes they call threadsafe may I use boost::mutex for the locking? or must I write my own mutex such as the one described here

//An openmp mutex.  Can this be replaced with boost::mutex? 
class Mutex {  
public:
    Mutex() { omp_init_lock(&_mutex); }
    ~Mutex() { omp_destroy_lock(&_mutex); }
    void lock() { omp_set_lock(&_mutex); }
    void unlock() { omp_unset_lock(&_mutex); }
private:
    omp_lock_t _mutex;
};

Edit, the link above to the openmp mutex seems to be broken, for anyone interested, the lock that goes with this mutex is along these lines

class Lock
{
public:
    Lock(Mutex& mutex) 
        : m_mutex(mutex), 
    m_release(false) 
    { 
        m_mutex.lock();
    }

    ~Lock() 
    {
        if (!m_release) 
            m_mutex.unlock(); 
    }

    bool operator() const 
    {
        return !m_release; 
    }

    void release()
    {
        if (!m_release)
        {
            m_release = true;
            m_mutex.unlock();
        }
    }

private:
    Mutex& m_mutex;
    bool m_release;
};
  • 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-05-22T11:35:58+00:00Added an answer on May 22, 2026 at 11:35 am

    You should not mix synchronization mechanisms. E.g. current pthreads mutex implementation is based on futex and it is different from previous pthreads implementations (see man 7 pthreads). If you create your own level of abstraction, you should use it. It should be considered what is your need – inter-thread or inter-process synchronization?
    If you need cooperation with code that uses boost::mutex, you should use boost::mutex in place of open mp.
    Additionally IMHO it is quite strange to use open mp library functions to realize mutex.

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

Sidebar

Related Questions

All too often I want a WPF slider that behaves like the System.Windows.Forms.TrackBar of
All, I currently have two projects that are under SourceSafe that I am unable
C++0x thread library or Boost.thread define non-member variadic template function that lock all lock
C++0x thread library or Boost.thread define a non-member variadic template function that locks all
All my PHP pages work fine but there is one PHP page that used
I have a multithreaded server application that needs mutex locks over some shared memory.
I have about 50 web-sites, load-balanced across 5 web-servers. They all use Enterprise Library
I have a MFC document/view C++ graphics application that does all its drawing to
I've written a C++ library that does some seriously heavy CPU work (all of
All coroutine implementations I've encountered use assembly or inspect the contents of jmp_buf .

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.