Re: threads



"Dr. Gerhard Dieringer" wrote:
> 
> Hi all,
>... 
> The next idea was to start two pthreads, one runs the gtk_main_loop and
> the other tries to
> read the IRRC-data, without first looking, if data is available. This
> 'solution' doesn't waste
> CPU-time, but it has the drawback, that it doesn't work :-((.
> 
> I got the following error message:
> Gdk-ERROR **: BadLength (poly request too large or internal Xlib length
> erro
>   serial 726 error_code 16 request_code 15 minor_code 0
> 

Threading in GTK is apparently pretty rough. Apparently you're supposed
to do all your GUI type stuff in one thread and use some sort of IPC
mechanism to control the GUI from the other thread.

Why not break your IR reader thing out to a separate process that uses
select to only read the IR port when there's data. Install a SIGUSR1
handler in your main app, and only signal your app when you've got data
(You can forward it over any IPC mechanism that takes your fancy.)

I think you can do this with threads too, but I've never tried
intra-thread signalling. There's a blurb on intra-thread signalling in
the pthread_kill man page.

There's lots of fun reading on the web and in the following man pages:
ipc(2)
kill(2)
signal(2)
mkfifo(3)

The web has quite a bit of useful information on UNIX IPC. It's
definitely worth doing a couple of hours of research to see what's
possible.

I might be able to turn up some example code on doing something similar
using SysV message queues and signal handling. If you're interested in
that, drop me a note.

-- 
Bruce Ide                                           
bruce.ide@echostar.com
http://www.paratheoanametamystikhood.net





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]