At 02:27 PM 12/5/2006, Christopher Bland wrote: > >> Based on suggestions from this mailing list I've implemented a pipe to > >> pass data from my other processes to the main GTK thread. I noticed > >> that when writing to the pipe there was a long delay before it was > >> handled. I'm assuming this is because it was a pending event. > >>
><snip...> >I'm pretty sure this is exactly what I've been seeing. Within my app I >have a 'clicked' event >attached to a button which basically starts all of my processing. Within >this callback I call >my main C++ routine which creates my objects and starts doing work. My app >is multi- >threaded but I had such a headache trying with the threads_enter/leave and >someone >suggested using pipes and use g_io_add_watch to "watch" a pipe. > >Within one of my C++ routines I write to the pipe, but the "watch" routine >does not get >called during execution of my threads. When control is given back to the >GUI thread (hence >my call to gtk_main_iteration()) then the "watch" routine gets fired off. > >I wanted to use the "watch" routine to move my progressbar and update the >statusbar in my >application and I'm having such a hard time getting it working with my >threads. > > >typically people will open (pipename, O_WRONLY | O_NONBLOCK) just to > >open the file with out blocking, and then fcntl(fd...) to set it back > >to blocking mode... then you might go ahead and select() the fd to know > >if the pipe is ready to receive one byte of data without blocking > >(maybe select()/write()ing one byte at a time until the buffer to write > >is finished... always returning to the main loop when it would block). > >I'm doing this as well. I basically followed the following example: >http://wwwtcs.inf.tu-dresden.de/~tews/Gtk/catch_signals.c Did you notice any abnormal CPU usage? That web site is really useful, but it didn't point out that you need to handle G_IO_HUP, G_IO_NVAL, (and maybe G_IO_PRI). Handling these helped my troubles, but I don't know if these have anything to do with your trouble. > >Remember that this heavily depends on what you are going to do with > >the pipe, do you want the reader to block in read() all the time ? > >do you want the writer to block in write() and have the reader > >test for a readable condition on the file descriptor before reading > >a byte ? do you want to use nonblocking read/write operations on both > >ends and just buffer the data in the pipe ? it can get complex. > > > >Cheers, > > -Tristan > >I really would like to be able to write to the pipe from my threads, have >the GUI read from >the pipe and then update my progress/status bars based on the data within >the pipe. If >anyone has any suggestions I would greatly appreciate it. I thought I was >on the road to >success but now I'm starting to doubt myself. > >Thanks. Daniel Yek _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list