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

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?

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.

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.

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.

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.

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.

Who is online

Users browsing this forum: Google [Bot] and 6 guests

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