Subject:
Re: [nanogui] multi-threaded app: problem and suggestion; patch
From:
Petr Ovtchenkov ####@####.####
Date:
23 Aug 2005 19:05:51 +0100
Message-Id: <200508232205.36354.ptr@island.plnet.ru>
On Tuesday 23 August 2005 20:43, Greg Haerr wrote:
> Hi Petr -
> I've been on vacation. I will take a look at your patch and
> try to find some ways to test it. If you could send any more explanation,
> that would be great. If this is a serious bug, we need to add
> the fix to CVS.
>
Thanks for you attention, Greg!
The test scenario may be following (this is a case when nano-X server and
nano-X client is different applications).
1. Start thread that run main loop:
int main_loop_func( void * )
{
GR_EVENT ev;
while ( 1 ) {
GrGetNextEvent(&ev);
switch ( ev.type ) {
case GR_EVENT_TYPE_EXPOSURE:
/* sleep(2); */
break;
}
}
return 0;
}
2. After we ensure that main_loop_func started, start
'window creation' thread:
int build_gui( void * )
{
GR_WINDOW_ID rid, wid, wid2;
GR_GC_ID gc, gc2;
rid = GrNewWindow( GR_ROOT_WINDOW_ID, 0, 0, 50, 50, 2, WHITE, RED );
GrMapWindow( rwid );
wid = GrNewWindow( rid, 10, 10, 30, 30, 2, BLACK, BLUE );
GrSelectEvents( wid, GR_EVENT_MASK_EXPOSURE );
sleep(3);
gc = GrNewGC();
GrSetGCForeground( gc, WHITE );
GrSetGCBackground( gc, BLACK );
GrMapWindow( wid );
GrFlush();
sleep(3);
wid2 = GrNewWindow( wid, 10, 10, 10, 10, 2, BLACK, BLUE );
GrSelectEvents( wid2, GR_EVENT_MASK_EXPOSURE );
sleep(3);
gc2 = GrNewGC();
GrSetGCForeground( gc2, WHITE );
GrSetGCBackground( gc2, BLACK );
GrMapWindow( wid2 );
GrFlush();
return 0;
}
The deadlock happens because in time of call GrNewWindow, GrNewGC, etc.
(that do mutex lock) the mail_loop_func wait on select call inside same
mutex lock.
This is artificial example derived from bit more complex C++ application.
The patch's part for case when nano-X server linked with application,
really don't solve main problem. Ignore it in first approach. Now I have
much better solution (but it essential multithreaded). I will send this
suggestion a bit later.
What about external libs and gcc version patches?
Best regards,
- ptr