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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:15:07+00:00 2026-05-13T18:15:07+00:00

This is a difficult problem to describe so please let me know if anything

  • 0

This is a difficult problem to describe so please let me know if anything is unclear.

I am trying to solve a possible deadlock situation in my C++ app and I am having trouble visualizing an appropriate solution. The restrictions placed on me by the two libraries I am trying to connect make my problem very complex and troublesome but it can all boil down to a simple diagram. Quite simply I have a situation like so

Python    |                 Thread 1                  Thread 2
          |
Action 1 -|-> GIL LOCK -->  Random Calls
Action 2  |   GIL LOCK <----------------------------- [Action 2]
          |                 Action 1 -- signals --->  Do_Action_1
          |                 Wait Forever              Wait on Action 2

Action 2 happens to be a timer firing, the library I am using has this timer code that will call functions after a set amount of time.

Trouble occurs when a timer fires while I am destroying the timer handler (Action 1). The timer handler will wait for the timers to finish their functions and the timer functions cannot finish because they are waiting to call a python function. In order to get into python they need to take the GIL which is being held by the timer handler destruction action.

I am wondering if its possible for me from Thread 1 to interrupt its wait on the GIL and unwind its stack to put it out of harms way of this deadlock. Although I fear going down to far into specific OS implementations I just can not think of any better solution.

In other words, I want to cancel the Action 2 call from thread 1. Is this in ANY way possible?

I should mention that I cannot edit the operation in Thread 2 ie, I cannot edit that library that is managing that thread.
I can modify python’s GIL lock to maybe be a try lock or a timed lock or maybe even a wait on a condition but that would be really hard to pull off.

I suppose the best solution would be to modify python to wait on the gil and a named condition that my Thread 1 can signal when I want to cancel its wait on the GIL. But before going down that route I want to know if I am missing anything.

  • 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-13T18:15:08+00:00Added an answer on May 13, 2026 at 6:15 pm

    If you’re destroying the timer handler, I figure you’re exiting the program. Before you try to exit and begin killing the timers, can you set a flag to prevent Action 1 and have Thread 1 terminate itself? I hope I’m reading your diagram right, because it doesn’t exactly match with the text…

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

Sidebar

Related Questions

I'm having a difficult time expressing this problem, so bear with me and please
I have been trying to tackle this problem , but I am having difficulty
This is a difficult and open-ended question I know, but I thought I'd throw
This might be a bit difficult to explain in writing, so please bear with
I know this will be a difficult question, so I am not necessarily looking
Need help with this SQL Server 2000 procedure. The problem is made difficult because
I've found it very difficult to find any existing documentation on this. What I'm
It's surprising how difficult it is to find a simple, concise answer to this
This is kind of a hard question to describe, and I've searched for about
This is fairly difficult to explain. I am working on a text adventure at

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.