Re: High CPU usage with glib main loop



On Wed, Jun 19, 2002 at 10:45:32PM +0200, Morten Brix Pedersen wrote:
Hi,

I have a GTK app. which uses sockets to communicate with a server, I have added
a watch on the file descriptor with g_io_add_watch() and everything works just
fine. However, sometimes the CPU usage of the app. goes to 100% and it seems
that the time is used in the glib main loop, attaching to the process in gdb
and pressing ^C almost always results in poll().

It's not because data is coming in on the socket all the time, CPU usage
is at 100% even when the client is idling.

A minor note: It *seem* that it only occurs when connected to two
servers (that is, two sockets and therefor two watches)

Does anyone have any ideas on how to fix this?

Thanks.

  - Morten.
---end quoted text---

Well, I had the same problem.. but it ocurred only when I had
a dead socket been watched.. I mean, the other side closed the
connection, or even me, and I didn't remove glib's watcher from
it.. then I used to get 100% cpu usage..
Try catching the signal SIGPIPE (this, by default, kills your
program) and take care about reading 0-length strings.. that
means that the socket were closed by the other side..

[]'s
-- 
Marcelo R Leitner <mrl netbank com br>



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