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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:08:38+00:00 2026-05-24T22:08:38+00:00

I have a problem regarding the behaviour of the pthread function pthread_rwlock_wrlock . The

  • 0

I have a problem regarding the behaviour of the pthread function pthread_rwlock_wrlock. The specification linked above states that when one thread has locked the lock for writing and the same thread locks it again, it results in undefined behaviour (I could actually observe this in that on x86 Linux calling this function is a noop and on PowerPC Linux it stalls the thread).

The behaviour I need would be a read write lock that has the following characteristics:

  • read-locking by a thread succeeds if:
    • the lock is not held by any thread
    • the lock is only read-locked by zero or more threads (including the calling thread) and possibly read- or write locked by the calling thread
  • write-locking succeeds when:
    • the lock is not held by any other thread
    • only the current thread is holding the lock (for reading or writing)

With a pthread_mutex_t, the recursiveness of the lock can be controlled via an initialization flag, but this is not possible for pthread_rwlock_t.

What are my options? I’ve never actually had to implement this kind of concurrency primitive in C, and I think I’m missing some obvious solution here.

  • 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-24T22:08:40+00:00Added an answer on May 24, 2026 at 10:08 pm

    To be honest, recursive locking does have some uses but generally it’s a hack. I can’t seem to find the article right now, but Butenhof has a nice rant on this.

    Back to the question. You could keep a thread-specific flag that signals: "I have the lock". Set it right after locking and unset it before unlocking. Since this is the only thread accessing it, you should be safe. So when trying to lock you simply need to check: "Hey, is this thing locked already?".

    As a side note: are you sure the design is okay if a thread tries to lock twice ?

    EDIT

    Found the article.

    But if that’s all that’s necessary, why does POSIX have recursive
    mutexes?

    Because of a dare.

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

Sidebar

Related Questions

I have a problem regarding the datediff MYSQL function, I can use it and
I have a problem regarding getting the path of a user control. The scenario
I have a problem regarding StartUp Url in WPF. I have a LoginView.xaml and
I have a question regarding a problem with L2S, Autogenerated DataContext and the use
I actually have two questions regarding the same problem but I think it is
I have problem in some JavaScript that I am writing where the Switch statement
I have a curious problem in jQuery regarding order of execution. The code below
I have a strange problem regarding suggestion items for an AutocompleteView on Android 2.2.
I am facing a strange problem regarding Hooking. I have a procedure which acts
I have a rather large program that have some odd behaviour once in a

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.