IO Error Handling In Threads

Hi Everyone,

I noticed that an X lib IO error causes the process to exit. I believe the default X lib IO handler calls 'exit' where then the entire process goes down.

I realize it is possible to set your own handler to handle X lib IO errors with a call to XSetIOErrorHandler. However, still, after calling my own X lib IO error handler, the process still exits.

My issue is this:

What if I create a thread that makes a connection to a Remote X server where the cable to the X server is suddenly cut. I would get the following error:

"XIO: fatal IO error 110 (Connection timed out) on X server "192.10.20.30:0.0"
after 151 requests (151 known processed) with 0 events remaining.
"

In such a case, I would like my thread to die off. Instead, my entire process dies off. So, if I had 4 threads in 1 process that has X connections to their corresponding X servers and ONE of the X servers goes down for that thread (broken connection), the entire process (which includes the other 3 threads with their own X connection) goes down too with the entire process exiting. Doesn't seem very friendly!

Is there a way to prohibit 'exit' from being called? Or what are workarounds for this?

Thanks!

Jason


dpeterc

dpeterc's picture

I use mulitple processes

I use mulitple processes (but not threads) in my code, but I am careful not to call any X related function in the children processes. I think this is the easiest approach, since you can usually divide your program logic in to UI thread(process) and worker threads (processes).

Note that when the child process is supposed to die, I call
_exit(0); not exit(0);
so that the child does not close my X session.
http://www.unixguide.net/unix/programming/1.1.3.shtml
So this might be the first thing to try.

X and Motif are supposed to be thread safe.
Using a quick google search, I found that you need to call
XInitThreads()
http://h71000.www7.hp.com/doc/732final/6663/6663pro_010.html
and you need to lock the sections dealing with X code
XtProcessLock() XtProcessUnlock()
I don't know if you did any of those.


JasonCA

JasonCA's picture

Hi Peter, You are a kind

Hi Peter,

You are a kind guy! Thanks for your attention and help. I do appreciate it :).

Jason