Last time I checked, you couldn't use threads and X in the same process, because the X event dispatcher conflicts with the thread scheduler. I spent some time getting it to work right, by re-writing the X dispatcher to run in its own thread, but the result was not satisfactory. That was several years ago, maybe things have changed since then.