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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:47:00+00:00 2026-05-24T20:47:00+00:00

In my GUI, I have a list store treeview in my main window. When

  • 0

In my GUI, I have a list store treeview in my main window. When the user double clicks a row, a dialog pops up. The problem is that the data I populate in the dialog box takes a while to process, so what I’ve done is started a thread (using boost threads) to do the dialog box calculations.

In main:
.......
g_signal_connect (G_OBJECT (m_treeview), "row_activated", G_CALLBACK (m_row_activated),
                  (gpointer) main_window);
.......

In m_row_activated:
.........
// combo_box and dialog are GtkWidget* global variables 
create_dialog(dialog, combo_box); // function creates the combobox
set_combo_box_with_loading_message;
gtk_widget_show_all (dialog);
thread m_thread (bind (&do_dialog_calculations, data1, data2, combobox));
.........

In do_dialog_calculations:
.........
// do_calculations takes about 15 seconds to complete
do_calculations(MyData data1, MyData data2, combobox);
gdk_threads_enter();
gtk_combo_box_append_text(...);
gdk_threads_leave()

Everything works fine (i.e. when the user double clicks a row, a dialog pops up immediately with a loading message and it is populated eventually when the thread returns), but my problem is when the user closes the dialog before do_calculations in do_dialog_calculations completes. If the dialog is destroyed, my combobox within it will be destroyed and my call to gtk_combo_box_append_text will seg fault.

I tried to test the combo box before updating it:

In do_dialog_calculations:
.........
do_calculations(MyData data1, MyData data2, combobox);
gdk_threads_enter();
if (GTK_IS_COMBO_BOX (combobox))
   gtk_combo_box_append_text(...);
gdk_threads_leave()

but this results in a deadlock at the call to GTK_IS_COMBO_BOX. I think this is beause GTK_IS_COMBO_BOX probably calls gdk_threads_enter(). I’ve also tried testing for NULL

 if (combobox == NULL)

but that doesn’t seem to work either. Any suggestions on how to get around this problem?

UPDATE: The deadlock at GTK_IS_COMBO_BOX only occurs if I close the dialog immediately after it opens (i.e. before do_calculations() completes. If I just let the dialog sit, it will eventually update. Also, if I switch the combobox check before writing calling gdk_threads_enter():

if (GTK_IS_COMBO_BOX (combobox)
{
   gdk_threads_enter();
   gtk_combo_box_append_text(...);
   gdk_threads_leave();
}

No deadlock occurs when I destroy the dialog before this code executes. However, I’m afraid of the rare possibility that the user will close the dialog after the GTK_IS_COMBO_BOX check completes.

PS – I use threads to do my dialog box calculations because the dialog boxes are non modal, and I want the user to be able to do other things with the main UI while the dialog boxes populate.

  • 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-24T20:47:01+00:00Added an answer on May 24, 2026 at 8:47 pm

    I think this is beause GTK_IS_COMBO_BOX probably calls gdk_threads_enter()

    I don’t think this is the case. These macros are generally pretty simple and I wouldn’t expect it to take a lock. In fact, as far as I can tell the whole idea of gdk_threads_enter is that the library itself shouldn’t call this, only code that knows it’s running in another thread should.

    Here’s my idea: Did you forget to call g_thread_init and gdk_threads_init?

    Also, one thing to keep in mind… By default, gdk_threads_enter is not using a recursive mutex. Though some people have religious objections to recursive mutexes, it’s possible to have gdk_threads_enter use one:

    static GStaticRecMutex my_gdk_lock;
    
    static void my_gdk_lock_enter() {g_static_rec_mutex_lock(&my_gdk_lock);}
    static void my_gdk_lock_leave() {g_static_rec_mutex_unlock(&my_gdk_lock);}
    
    // ...
    
       g_thread_init(NULL);
    
       g_static_rec_mutex_init(&my_gdk_lock);
    
       gdk_threads_set_lock_functions(G_CALLBACK(my_gdk_lock_enter),
                                      G_CALLBACK(my_gdk_lock_leave));
    
       gdk_threads_init();
    
    // ...
    

    Update: From your comment it sounds like you have a race condition between destroying the dialog and populating the combo box. One potential solution is that you bump up the reference count of the combo box (i.e. gtk_widget_ref) so that it doesn’t get freed while your asynchronous worker is doing something. Then release it with gtk_widget_unref when the other thread no longer needs the pointer.

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

Sidebar

Related Questions

I have a GUI that is going to do a lot of disparate tasks.
I have a GUI C++ application (Visual Studio 2008) that needs to be converted
I have a GUI tool that manages state sequences. One component is a class
I have a GUI that is issuing commands to a web server based on
Does MSTest have standalone GUI similar to nUnit that lets me use it and
I have a List<Polyline> that I need to generate in a second thread so
I have a list of classes, but different children have different properties that need
I have a list of about 600 jobs that I can't delete from the
I have an existing app with a command-line interface that I'm adding a GUI
i have a large list of static data from a server that i load

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.