I have an X application I wrote using gcc-2.96-85 on RedHat 7.0. I've upgraded to gcc-3.3.1 on RedHat 9 (XFree 4.3.0). I'm running into some strange behaviors in the new version.

        - the window does not refresh when uncovered
        - the mouse callbacks are disabled
        - Ctrl-C required to close window (XtAppMainLoop never returns)

I believe the problem may have something to do with running XtAppMainLoop in a thread. I have a test that attempts to take a simple X application and run the XtAppMainLoop in a thread, but instead of experiencing the problems above, the window doesn't come up at all.

I've attached the test code. When I call the runinthread function directly, it works, but nothing happens when it's in a thread. Maybe I'm just using threads improperly.

Thanks,
Dan Mergens
#include <Xm/MainW.h>
#include <Xm/List.h>
#include <pthread.h>
#include <iostream>

using namespace std;

void* runinthread( void* data )
{
cout << "runinthread()\n";
        XtAppContext *app = static_cast<XtAppContext*>(data);
        XtAppMainLoop(*app);
cout << "runinthread() end\n";

        return 0;
}

int main(int argc, char *argv[])
{
        Widget toplevel, main_w, list_w;
        XtAppContext app;
        Pixmap pixmap;

//      XtSetLanguageProc(0, 0, 0);

        XInitThreads();
        XtToolkitThreadInitialize();
        toplevel = XtVaAppInitialize(&app, "Demos", 0, 0, &argc, argv, 0, 0);

        main_w = XtVaCreateManagedWidget("main_window", 
                                         xmMainWindowWidgetClass, toplevel, 0);

        list_w = XmCreateScrolledList(main_w, "main_list", 0, 0);
        XtVaSetValues(list_w, XtVaTypedArg, XmNitems, 
                XmRString, 
                "Red, Green, Blue, Orange, Maroon, Grey, Black, White", 53,
                XmNitemCount, 8, XmNvisibleItemCount, 5,
                0);
        XtManageChild(list_w);

        XtVaSetValues(main_w, XmNworkWindow, XtParent(list_w), 0);

        XtRealizeWidget(toplevel);
//      XtAppMainLoop(app);

        pthread_t xthread;
        pthread_attr_t attr;

        pthread_attr_init( &attr );
//      runinthread(&app);
        int status = 0;
        status = pthread_create(&xthread, 0, &runinthread, &app);
//      if (status != 0) return 1;
        pthread_join(xthread, 0);
        return status;
}

Reply via email to