GThread usage in the panel

Brian J. Tarricone bjt23 at
Sat Jul 24 20:45:19 CEST 2004

Benedikt Meurer wrote:

> Jasper Huijsmans wrote:
>> Hey all, especially plugin writers,
>> Yesterday, I committed a patch from Brian that adds thread 
>> initialization and locking to the panel.
>> I had hoped that this would not affect anything that wasn't using 
>> threads, but it seems this is not the case: idle or timeout functions 
>> need to use gdk_thread_enter (); ...; gdk_thread_leave(); to make 
>> sure there is no conflict with other threads accessing gtk.
>> Since there are currently no plugins using threads, this problem 
>> won't show up yet, but it will when e.g. the menu plugin starts using 
>> threads.
>> If you implement this you can depend on the panel version 4.1.7.
> To easy the transition, I added some magic to the XFCE_PANEL_PLUGIN m4 
> macro. It now tests if the panel is threaded and if so, it defines 
> XFCE_PANEL_THREADED=1 and sets XFCE_PANEL_LOCK to gdk_threads_enter 
> and XFCE_PANEL_UNLOCK to gdk_threads_leave. If the panel isn't 
> threaded, XFCE_PANEL_THREADED won't be defined and XFCE_PANEL_(UN)LOCK 
> will be no-ops.
> So, for panel plugin writers:
> 1) get the latest depends.m4 from Xfce CVS (I've already updated the 
> depends.m4 files in berlios CVS, so if your plugin is hosted at the 
> xfce-goodies project, you don't need this step)
> 2) Locate idle/timeout functions and place XFCE_PANEL_LOCK() at the 
> beginning of the function and XFCE_PANEL_UNLOCK() at the end of the 
> function (_before_ the return of course :-).

an important note.  this means you CANNOT use these functions for 
anything but idle/timeout functions.  if you call one of these functions 
from anywhere in the main thread or in the gtk main loop, the panel will 
hang.  if you have a function that you use as a timeout/idle function 
and that you just call normally, you'll need to wrap it in another 
function that calls XFCE_PANEL_LOCK/UNLOCK() around the function call.  
sorry i'm not explaining this perfectly, but if anyone's confused, let 
me know and i'll provide an example.


More information about the Xfce4-dev mailing list