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 8080185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:20:18+00:00 2026-06-05T16:20:18+00:00

I assumed that I would be able to create 2 different omp_lock_t’s, and lock

  • 0

I assumed that I would be able to create 2 different omp_lock_t’s, and lock them independently of each other. I tested the following section of code with gcc 4.4 and gcc 4.6.1 and got the same output:

omp_lock_t lockA;
omp_lock_t lockB;
omp_init_lock(&lockA);
omp_init_lock(&lockB);

std::cout << "Lock B is: " omp_test_lock(&lockB) << "\n";
omp_set_lock(&lockA);
std::cout << "Lock A set\n";
std::cout << "Lock B is: " omp_test_lock(&lockB) << "\n";

omp_set_lock(&lockB);
...

This code produces the following output:

Lock B is: 1
Lock A set
Lock B is: 0

then it deadlocks on the omp_set_lock(&lockB) attempt.

Is it not possible to create two different locks and use them independently? If it is possible, what is the correct way to set up these locks?

Thanks

  • 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-05T16:20:20+00:00Added an answer on June 5, 2026 at 4:20 pm

    The code works as expected. I’m assuming that you have a misunderstanding about what omp_test_lock does (especially since the name is admittedly very misleading).

    omp_test_lock tries to acquire a lock. But unless omp_set_lock, it doesn’t block until it has successfully acquired the lock. But that’s the only difference. Notably, after the first “test” (which isn’t just a test), lockB is acquired, that’s why the second “test” fails, and why the subsequent omp_set_lock(&lockB) deadlocks.

    And just to make this clear: yes, you can use multiple locks.

    omp_lock_t lockA;
    omp_lock_t lockB;
    omp_init_lock(&lockA);
    omp_init_lock(&lockB);
    
    omp_set_lock(&lockA);
    std::cout << "Lock A set\n";
    omp_set_lock(&lockB);
    std::cout << "Lock B set\n";
    …
    

    This code won’t deadlock.

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

Sidebar

Related Questions

I assumed that this would provide me with the list of follower names instead
Possible Duplicate: Loop code for each file in a directory I assumed that I
I'm facing a problem that I assumed would be very easy to solve but...
I've tried to create a producer-consumer stack, based on notification events, that would allow
I have a system-wide manual reset event that I create by doing the following:
I would like to be able to create a socket in C# and marshal
I have a client application that should be able to handle the following: 1)
While I would assume that in VC++ this would be a no brainer, it's
I would assume that most User-defined Exceptions are for Business Logic level exceptions, but
Let's assume that I have a complex hash reference $hash_ref , and I would

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.