GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Jul 29, 2014 2:47 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Fatal IO errors on X server :0.0.
PostPosted: Wed Feb 22, 2012 4:21 pm 
Offline
Familiar Face

Joined: Tue Jan 31, 2012 10:44 am
Posts: 8
Dear all,

I'm working on a dynamic plotting application in which parent process is the producer of data and child process is the dynamic plotter. It works well for one dynamic plot i.e. one child process. When I try to do multiple plots by opening multiple windows in child processes using

window=gtk_window_new(GTK_WINDOW_TOPLEVEL);

I get following errors

<unknown>: Fatal IO error 0 (Success) on X server :0.0.
<unknown>: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.

Any pointers to solve this are appreciated.


Top
 Profile  
 
 Post subject: Re: Fatal IO errors on X server :0.0.
PostPosted: Wed Feb 22, 2012 6:33 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 734
Location: UK
Hi,

It looks like you are trying to use GTK with multiple threads without using GDK locking. Note that GTK/GDK is thread aware but not thread safe. See the documentation at http://developer.gnome.org/gdk3/stable/gdk3-Threads.html.

You do not state how your processes are created as there are certain other restrictions that must be obeyed. Any more information would be useful and are multiple threads really needed.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Fatal IO errors on X server :0.0.
PostPosted: Wed Feb 22, 2012 7:14 pm 
Offline
Familiar Face

Joined: Tue Jan 31, 2012 10:44 am
Posts: 8
Thanks for the suggestion errol. I'm not using threads at the moment. I'm currently using multiple processes. Multiple processes are needed because of the dynamic plotting requirement. The parent process writes data to shared memory & a child process (created using fork) creates the top level window, packs Gtkgraph widgets in it and reads data from shared memory & does dynamic plotting using timer handlers. These errors come when I try to open multiple plot windows simultaneously i.e. multiple children processes doing dynamic plotting. The scope of all Gtkwidgets is limited to the child process. Gtkmain loop and all events are handled in the child process. Parent process only writes data to the shared memory. Is any restriction violated in this design? Could you please direct me to where I can find restrictions to be obeyed for processes?


Top
 Profile  
 
 Post subject: Re: Fatal IO errors on X server :0.0.
PostPosted: Wed Feb 22, 2012 7:49 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 734
Location: UK
Without seeing the code it is a bit hard to tell exactly what is going on, and I am sure that it is a bit too big to post here.

Going by your description it sounds like you are forking many processes each using its own GTK main loop.

There could be several problems here first one is related to this I found by doing a search http://developer.gnome.org/gtk-faq/stable/x505.html. So if you use fork() and then use exit() you have effectively closed the socket to the X11 server.

Another problem could be that you have a X11 socket connection created in the parent via GTK and then trying to reuse it in the child processes with the data entering the socket in a bad order.

I would consider rewriting the code so as to not use fork(). Going by your description of what you want done I do not think that you need to use fork(), you also do not need to use threads. But if you do need to use threads you just need one thread to deal with the graphical user interface (GTK/GDK/Cairo etc) and one thread to read in the data and place it in a buffer to be processed by the GUI thread.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Fatal IO errors on X server :0.0.
PostPosted: Wed Feb 22, 2012 8:51 pm 
Offline
Familiar Face

Joined: Tue Jan 31, 2012 10:44 am
Posts: 8
Thanks for the link errol. I replaced exit with _exit, but the error stays put. These errors come before i close the window which is when exit is called in the quit event handler. Parent process accesses only shared memory to write data & returns back to the application. It does not use any Gtk widgets. I agree that if I somehow get rid of the fork, these errors will cease to exist. But I'm not able to visualize how I can do dynamic plotting without using a multi-process/multi-threaded design?

Application i.e. parent process calls the plot_init function in which parent forks a child process which enters gtk main loop. Parent immediately returns back to the application to read incoming data & update shared memory. So, I need one process which will stay in gtk main loop for dynamic plotting & one process to read new data & update shared memory.

Any pointers on how to get rid of the fork call will be highly appreciated.


Top
 Profile  
 
 Post subject: Re: Fatal IO errors on X server :0.0.
PostPosted: Thu Feb 23, 2012 12:06 pm 
Offline
Familiar Face

Joined: Tue Jan 31, 2012 10:44 am
Posts: 8
Hi,
These errors were coming because gtk_init was called in parent process. Now that I've shifted the enire gtk related code to child process & hence calling gtk_init from child process, these errors are not coming anymore. Thanks for the help.


Top
 Profile  
 
 Post subject: Re: Fatal IO errors on X server :0.0.
PostPosted: Fri Feb 24, 2012 7:31 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 734
Location: UK
Good to hear that you have fixed your application. I would still suggest that you avoid using fork() partly due to the large over heads involved. For a small application like a small mail server it is probably OK but for a GUI with large data structures pipes to the X11 server and other over heads this may be a bit too much. The way fork() works on Linux is to do a copy on write once a fork of the application has been done. So as soon as a write to memory is done an interrupt is called in the system, a chunk of system memory has to be allocated and then data is copied before the write to memory is allowed to carry on. This copy to memory could be several mega bytes.

To get around this you need to keep a structure for a window that holds all the information that is needed for it such as the GtkWidget of the window, the id of a timer and anything else that is required.You can then keep a list of the open windows by using these structures of data, so you create a structure and fill it in and add it to the list when you want a new window and delete it from the list and do any tidying up when you want to remove a window. This way you should be able to get way with one gtk_main() and use threads to do data processing in the background if needed.

But without seeing any code I am unable to answer with any detail.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Fatal IO errors on X server :0.0.
PostPosted: Thu Apr 12, 2012 6:22 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 734
Location: UK
Hi,

Please start a new topic instead of added onto an already solved topic. This does help others when reading.

What you are doing is doing several plots via multiple threads and hence calling GTK/GDK from multiple threads which you can not do. Threads is a powerful tool, but can be missed used very easily, and misunderstood by many who do not know the pit falls that lay ahead.

I do not think there is a work around for you except to do everything from within a single thread.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group