Re: XForms: Some news about threads and Xforms and OpenGL...

From: Steve Lamont (spl@ncmir.ucsd.edu)
Date: Wed Mar 12 2003 - 18:10:37 EST

  • Next message: Nicolas Castagne: "Re: XForms: Some news about threads and Xforms and OpenGL..."

    # To subscribers of the xforms list from Steve Lamont <spl@ncmir.ucsd.edu> :

    > When a handler is added to handle expose events, the Xlib
    > sometimes generates GLX bad access errors ("attempt to acces private
    > ressource denied" - request X_GLXMakeCurrent) - and the program aborts.
    > It seems that handler for expose event cannot be added to a canvas
    > "possessed" by a thread.

    This is mostly an OpenGL problem.

    Basically, only one thread may own the GLXContext at any one time. If
    multiple threads try to access the same GLXContext simultaneously,
    disaster ensues.

    If you *must* access the context from multiple threads, you must
    bracket the critical with mutexes or somethign similar and be careful to
    release the context before exiting the critical section, as per the
    manual page for glXMakeCurrent():

         To release the current context without assigning a new one, call
         glXMakeCurrent with drawable set None and ctx set to NULL.

    Since the event handler callback is invoked from the main thread
    (defined as the one that call fl_do_forms() or its ilk), it is likely
    to tromp on any other threads which might try to draw to the canvas.

    For example:

        pthread_mutex_lock( &mutex ); /* Grabs the mutex when available */

        /* Grab the context */

        glXMakeCurrent( fl_get_display(), FL_ObjWin( canvas ), context );

        /* [do your GL stuff here] */

        /* Free the context */

        glXMakeCurrent( fl_get_display(), None, NULL );

        pthread_mutex_unlock( &mutex ); /* Hands the mutex back */

                                                            spl

        
    _________________________________________________
    To unsubscribe, send the message "unsubscribe" to
    xforms-request@bob.usuhs.mil or see
    http://bob.usuhs.mil/mailserv/xforms.html
    XForms Home Page: http://world.std.com/~xforms
    List Archive: http://bob.usuhs.mil/mailserv/list-archives/



    This archive was generated by hypermail 2b29 : Wed Mar 12 2003 - 18:11:34 EST