On Wed, Apr 29, 2009 at 10:03:44PM -0500, Maurice LeBrun wrote: > On Wednesday, April 29, 2009 at 21:58:03 (+0100) Andrew Ross writes: > > Further testing has shown that I can get rid of the segmentation fault by > > removing the call to XInitThreads in the OpenXwin function in xwin.c. > > According to the Xlib documentation: > > > > "The XInitThreads() function initializes Xlib support for concurrent > > threads. This function must be the first Xlib function a multi-threaded > > program calls, and it must complete before any other Xlib call is made. > > This function returns a nonzero status if initialization was successful; > > otherwise, it returns zero. On systems that do not support threads, this > > function always returns zero. > > > > It is only necessary to call this function if multiple threads might use > > Xlib concurrently. If all calls to Xlib functions are protected by some > > other access mechanism (for example, a mutual exclusion lock in a toolkit > > or through explicit client programming), Xlib thread initialization is > > not required. It is recommended that single-threaded programs not call > > this function." > > .. > > In particular, with the tk support there may be other Xlib calls > > elsewhere which are not protected. It is also probable that > > XInitThreads is not actually the first Xlib call in this case. > > It is not. In plframe.c the window is created by: > > new = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), > argv[1], (char *) NULL); > > which ultimately terminates in a call to XCreateWindow(). From the Tk > generic/tkWindow.c -- > > * tkWindow.c -- > * > * This file provides basic window-manipulation procedures, > * which are equivalent to procedures in Xlib (and even > * invoke them) but also maintain the local Tk_Window > * structure. > > The partial initialization of the xwin driver the plframe widget does after > that may not require the window to actually already exist -- I don't see any > explicit dependence, although it's been too long for me to remember if I ever > tried doing the two ops in reverse order. You might want to give this a try. > I.e. move the code > > /* Partially initialize X driver. */ > > pllib_init(); > > plsdev("xwin"); > pllib_devinit(); > plP_esc(PLESC_DEVINIT, NULL); > > above the call to Tk_CreateWindowFromPath().
I think I have convinced myself that XInitThreads is needed for the Tk case since we don't control all the Xlib calls. A quick web search suggests our symptoms are probably a result of Xlib calls being made before XInitThreads is called. I tried Maurice's suggestion, but this does not help. It is still not early enough. Adding a call to XInitThreads into the start of tkMain.c does solve the problem though. The additional call in xwin.c does not seem to be a problem. This leaves the basic xwin code unchanged and only affects the tk code, so I am happy to commit this ahead of the release and to re-enable HAVE_PTHREAD by default. Andrew ------------------------------------------------------------------------------ Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf _______________________________________________ Plplot-devel mailing list Plplot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-devel