Threads (WAS: RE: pthreads, pixmaps and event boxes : update lock s app BUT no-update frees app.)



Maybe someone could fill me in here.

Is it possible (from a theoretical standpoint) for the gtk to automatically
call gdk_threads_enter() and gdk_threads_leave()?  I just never understood
why the programmer had to make these calls...

-Michael

-----Original Message-----
From: flatmax [mailto:flatmax cse unsw EDU AU]
Sent: Thursday, March 15, 2001 12:55 PM
To: gtk-app-devel-list gnome org
Subject: Re: pthreads, pixmaps and event boxes : update locks app BUT
no-update frees app.


OK it turns out these errors were created by incorrect useage of the :
gdk_threads_enter();
gdk_threads_leave();
functions.

When threading, these functions SHOULD ONLY BE USED in the thread function
!

Matt

On Thu, 15 Mar 2001, flatmax wrote:

Here is the little problem (cited below) ... I wonder if it solvable by
hooking more 'gtk_widget_add_events' functions onto the event boxes ?

Firstly I have constructed some custom pixmap event boxes using the
following :

GtkPixmap **digitsGtk; // The digit GtkPixmaps
GtkWidget **digitsEventBox; // The event box for handling mouse presses
Where I use :

gtk_container_add(GTK_CONTAINER(digitsEventBox[i]),GTK_WIDGET(digitsGtk[i]))
;
To load the pixmaps into the event boxes.

The following function lets the user interact with the event boxes and
hence switch the pixmaps :
  void eventSetup(void){
    for (int i=0; i<digitCnt();i++){
      gtk_widget_add_events(GTK_WIDGET(digitsEventBox[i]),
                            GDK_BUTTON_RELEASE_MASK);
      gtk_signal_connect (GTK_OBJECT(digitsEventBox[i]),
                          "button-release-event",
                          GTK_SIGNAL_FUNC(digitPress), this);
    }
  }


During app operation either I have the choice of :
a] updating digit pixmaps during thread operation, but may not interact
   with the pixmap event boxes
b] No updating of the digit pixmaps by the thread during
   thread operation, but may interact blindly with the pixmap event boxes
   (blindly 'cause they aren't being updated !)

'a]' is accomplished by REMOVING the gdk_threads_enter() and
     gdk_threads_leave() update lockouts from the 'update' routine.
'b]' is accomplished by INCLUDING the gdk_threads_enter() and
     gdk_threads_leave() update lockouts in the 'update' function routine.

The update function looks something like so :
  void update(void){
    for (int i=0;i<digitCnt();i++){
      int which=/*digit value*/
      cout<<"Threads enter "<<i<<endl;
      gdk_threads_enter();

      cout<<"Set pixmap"<<endl;
      gtk_pixmap_set(digitsGtk[i], digitsGdk[which], digitsMasks[which]);

      cout<<"Threads exit"<<endl;
      gdk_threads_exit();
    }
  }

thanks
Matt





_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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