Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#4532 Tcl_WaitForEvent: CFRunLoop finished on MacOSX

obsolete: 8.6b1.1
Cliff Yapp

Using tcl 8.6cvs compiled for X11 graphics on Mac OSX, I have been attempting to get an application working whose purpose is to incrementally display an image onscreen as it is generated by a raytracer. To do this, the general approach is:

1. Set up the window and Tk Photo
2. Enter a loop where the image generation routine calls a function to put blocks into the photo (this is in C)
The loop:
a. Calls Tk_PhotoPutBlock to write the generated information
b. Calls Tcl_DoOneEvent(TCL_ALL_EVENTS|TCL_DONT_WAIT); to immediately update the view.

It's the latter step that seems to be failing: the window appears, but there is no visible output and the error on the command line is:

Tcl_WaitForEvent: CFRunLoop finished
Abort trap

If I comment out the Tcl_DoOneEvent line, the display eventually does show the image but only upon completion of the entire raytrace. This same code did succeed with Tcl/Tk 8.5 X11 on the Mac, although the 8.5 AquaTk results were similar to the above - it either didn't update until the end or produced the same error as seen above.

If any additional information or example code is needed I will do my best to supply it. Any help appreciated.


  • Cliff Yapp
    Cliff Yapp

    One important update I just found - the above behavior is observed only when raytracing using multiple cores, which may indicate that the issue is thread related - is Tcl_DoOneEvent supposed to be thread safe?

  • Tcl_DoOneEvent() is not thread safe if you share an interp between threads, please read up on the Tcl threading model. You must only call Tcl functions for a given interp on the thread that created that interp.

    Also, you can only use TkAqua on the main thread (i.e. display can only occur from the main thread), indeed TkAqua should only be initialized on the interps created on the main thread.
    The only safe Tcl cross-thread notifications are those based on Tcl_ThreadAlert(), e.g. the Tcl_Async* mechanism.

    FWIW, the "CFRunLoop finished" panic is just a safety mechanism for an unexpected return avlue in tclMacOSXNotify.c Tcl_WaitForEvent(), you can try to take that out (it is an indication that somebody called CFRunLoopStop() on a thread's runloop, which Tcl certainly never does itself, try finding out who calls this)

  • Cliff Yapp
    Cliff Yapp

    OK, so the fact that this code succeeded with the older X11 Tk compiled without corefoundation support would be considered accidental and is not a consequence of an intended design feature of Tcl/Tk? (I.e. even in that case where it did succeed it would be better practice to redesign the approach?)

    I'll take a look at the Tcl threading model (http://www.tcl.tk/doc/howto/thread_model.html, in case I need it later...)

    Thanks much.