X11 and pthreads - Xwindows

This is a discussion on X11 and pthreads - Xwindows ; After creating a thread, I know that I have to synchronize the thread with the main thread running the X11 event loop, and I know that a mutex is needed within the X11 thread. How is the mutex used so ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: X11 and pthreads

  1. X11 and pthreads

    After creating a thread, I know that I have to synchronize the thread with
    the main thread running the X11 event loop, and I know that a mutex is
    needed within the X11 thread. How is the mutex used so that X11 output
    from within the new thread does not get X11 out of sync and cause the
    application to crash?

    Is it something like this:

    X11 main thread
    ---------------
    x11_mutex.lock();
    ....process X11 event loop...
    x11_mutex.unlock();



    Other thread
    ------------
    x11_mutex.lock();
    ....do X11 stuff...
    x11_mutex.unlock();



    Or am I way off?


  2. Re: X11 and pthreads

    Tony O'Bryan wrote:
    |After creating a thread, I know that I have to synchronize the thread with
    |the main thread running the X11 event loop, and I know that a mutex is
    |needed within the X11 thread. How is the mutex used so that X11 output
    |from within the new thread does not get X11 out of sync and cause the
    |application to crash?

    X11 and Xt routines will do thread-safing if you tell them to.
    (Motif 2.1 will also be thread-safed by the Xt call.)

    if (!XInitThreads()) {
    printf("Xlib not thread safe\n");
    exit(1);
    }

    if (!XtToolkitThreadInitialize()) {
    printf("Xt not thread safe\n");
    exit(1);
    }

    --
    Mike Stroyan, mike.stroyan@hp.com

+ Reply to Thread