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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:42:24+00:00 2026-05-23T16:42:24+00:00

In my program, to create a barrier, the main thread sends signals to all

  • 0

In my program, to create a barrier, the main thread sends signals to all the other threads. Now, I want to check if the thread which is executing the signal handler had a mutex locked when the signal handler started. Is there any way to check that inside the signal handler?

  • 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-23T16:42:24+00:00Added an answer on May 23, 2026 at 4:42 pm

    Reading through your comments, it appears as though your program is a lot more complex than I thought. If you have 1000’s of mutexes, checking to see if they are locked in a signal handler is a bad idea. In fact, if your app is this highly threaded, mixing signals and threads is also an idea I think you should reconsider. The reason for this is mainly inherent in the fact that you can’t set a status flag and lock a mutex in an atomic fashion that would be signal-safe. In order to create the proper conditions to support updating a status entry for your mutex, as well as locking the mutex without being interrupted by a signal in the process, you’re going to have to create a bunch of code to wrap all your mutex-locking and unlocking functions in critical sections that block any signals the thread could receive, so that you can both lock/unlock a given mutex, as well as set/unset a flag for the mutex’s state that can then be read in the signal handler.

    A better solution would be to have only a single thread accept signals, with all the other threads blocking the signals you’re sending, including the main thread. Then, rather than having to send signals to individual threads, you can simply send signals to the entire process. Upon sending the signal, the only thread that is set for receiving signals and handling them waits with a call to sigwait() for the appropriate signal, and upon receipt, quickly checks an array of values to see which mutexes are set, and which specific thread owns them. For this information your array can be an array of values that are a structure type containing a pointer to the mutex, a locked/unlocked flag, as well as a pointer to the pthread_t of the thread that you can use to get the thread ID value from. For instance, you struct could look something like:

    typedef struct mutex_info
    {
        pthread_mutex_t* mutex_handle;
        pthread_t* thread_handle;
        int locked;
    } mutex_info;
    
    mutex_info mutex_info_array[NUM_MUTEXES];
    

    Then your other threads, without having to worry about asynchronous signal events, can simply update the array values every time they lock or unlock a specific mutex.

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

Sidebar

Related Questions

I need my program to create and edit a config file, which would contain
If i create a program, which in one small out of the way area,
I want to create a program that requests from the user 10 grades and
I have a large old program which has some rather complex graphical displays (all
I want to write a program (create an exe file) to uninstall a program
I have a program which create a new branch when I give it the
I have a program, when I click button 'Download', program create a new thread
I need to create program that creates a XML schema like below using System.Xml.XmlSchema
Can anyone recommend a program to create user manuals with? Not a markup language
I'm looking for a program to create window transparency within Windows XP; somewhat like

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.