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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:34:40+00:00 2026-05-23T11:34:40+00:00

While I am looking the man page of pthread_rwlock_unlock function, I noticed that the

  • 0

While I am looking the man page of pthread_rwlock_unlock function, I noticed that the func will return EPERM if the calling thread does not have the ownership of a rwlock.

Since the rdlock allows multiple threads to get the lock, there must be a data structure like a link or array to store the ownerid of one specific rwlock.

Here comes the question:

The rwlock is designed to achieve efficiency when the read operation is far more frequent than write operations, but if there are large number of different threads got the read lock, each time I call a pthread_rwlock_unlock(), it takes time to find out weather the calling thread is a valid owner. what is the time complexity of this scenario..

Thanks a lot guys 🙂

  • 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-23T11:34:41+00:00Added an answer on May 23, 2026 at 11:34 am

    n.m has provided a good answer. Your assumption of structures to hold the lock ownership is wrong on the linux implementation you tagged and is similar to the count method n.m. touches upon.

    Here is an edited version of the pthread_rwlock_t type from /usr/include/bits/pthreadtypes.h

      struct
      {
        int __lock;
        unsigned int __nr_readers;
        unsigned int __readers_wakeup;
        unsigned int __writer_wakeup;
        unsigned int __nr_readers_queued;
        unsigned int __nr_writers_queued;
        int __writer;
        int __shared;
        unsigned int __flags;
      } __data;
    

    You can see the count fields. Also pthread_rwlock_unlock.c does not return EPERM and most of the work revolves around checking writer ownership in pthread_rwlock_wrlock.c and pthread_rwlock_rdlock.c.

    You can test this with a small program to declare and initialize a lock and then just unlock it.

    So time complexity seem close enough to constant in this implementation but is earned by bailing on some features you may have thought or wanted to be there.

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

Sidebar

Related Questions

While looking over various PHP libraries I've noticed that a lot of people choose
While looking through the Spring MVC framework I noticed that, unless I misunderstand, its
While looking over some code, I found a function that seems to do exactly
While looking at a micro-optimization question that I asked yesterday ( here ), I
Background: Recently while looking at a structured text editor I noticed they used a
While looking through a 3rd party JavaScript API and example code I noticed the
While looking at this question and it's answers I thought that it would be
While looking through the built in Android themes/styles I noticed references to textColorPrimary, textColorSecondary
While looking at the unit tests that come with the standard ASP.MVC Web Project
While looking through analytics data I found a root domain pointing to a page

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.