GTK & Threads - Questioning safe practice.




i understand threads in gtk for the most part....
But what do you do when both functions call the same "share me function"
where that could simply be jsut a function that creates a gui image, or whatever.

since you have to impliment locking on the function, is it safe to unlock the main (since the function will again lock itself again)?

see below how share_me() is written and tell me if call_me() is valid?
If anyone could help out, that would be great!



main()
   init_threads()
   gtk_init()
     .
     .
    <create menu that calls function call_me()  here>
    pthread_create( ....... my_thread ..);
     .
     .
   gdk_threads_enter();
   gtk_main();
   gdk_threads_leave();
}


my_thread()
{
   while(keep_alive){
      gdk_threads_enter();
      <create menuu that calls function call_me_thr() here>
      gdk_threads_leave();
   }
}


call_me()
{
   .. do whatever...
   gdk_threads_leave();
   share_func();
   gdk_threads_enter();

}

call_me_thr()
{
  .. do whatever ...
  share_func();
}


share_func()
{
   gdk_threads_enter();

    ... do whatever ..

   gdk_threads_leave();
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]