Race condition in TGtk2WidgetSet (TGtkMessageQueue)
Original Reporter info from Mantis: wavebvg
-
Reporter name: Boris Glavin
Original Reporter info from Mantis: wavebvg
- Reporter name: Boris Glavin
Description:
In methods Lock/UnLock of TGtkMessageQueue
procedure TGtkMessageQueue.Lock;
begin
inc(fLock);
if fLock=1 then
{$IFDEF USE_GTK_MAIN_OLD_ITERATION}
EnterCriticalsection(FCritSec);
{$ELSE}
g_main_context_acquire(FMainContext);
{$ENDIF}
end;
procedure TGtkMessageQueue.UnLock;
begin
dec(fLock);
if fLock=0 then
{$IFDEF USE_GTK_MAIN_OLD_ITERATION}
LeaveCriticalsection(FCritSec);
{$ELSE}
g_main_context_release(FMainContext);
{$ENDIF}
end;
race status is possible
Steps to reproduce:
Execute multiple call PostMessage from another threads
Additional information:
It is possible to add critical section for solution of the problems:
procedure TGtkMessageQueue.Lock;
begin
EnterCriticalSection(FLockCritSec);
inc(fLock);
if fLock=1 then
{$IFDEF USE_GTK_MAIN_OLD_ITERATION}
EnterCriticalsection(FCritSec);
{$ELSE}
g_main_context_acquire(FMainContext);
{$ENDIF}
LeaveCriticalSection(FLockCritSec);
end;
procedure TGtkMessageQueue.UnLock;
begin
EnterCriticalSection(FLockCritSec);
dec(fLock);
if fLock=0 then
{$IFDEF USE_GTK_MAIN_OLD_ITERATION}
LeaveCriticalsection(FCritSec);
{$ELSE}
g_main_context_release(FMainContext);
{$ENDIF}
LeaveCriticalSection(FLockCritSec);
end;