Problems with glib's gcond?
- From: Benjamin Kahn <xkahn cybersites com>
- To: gtk-list redhat com
- Subject: Problems with glib's gcond?
- Date: Tue, 1 Feb 2000 13:57:36 -0500 (EST)
I'm having a problem with glib's gcond command. Are there known
problems with the sample code in the reference documentation? Basically, I
have 32 threads waiting on a gcond. And I have another thread which will
send up to 10 gcond signals in under a second. Only the last signal is
caught and handled, unless I put a sleep command in the loop. In other
words, when many signals happen at around the same time, gcond seems to
forget all but the last one. I'm using the code snippet from
http://developer.gnome.org/doc/API/glib/glib-threads.html#GCOND
So my code looks like this:
----------------------------=[ Code from the above address ]
void thread_give_work (work *data)
{
g_mutex_lock (conn_mgr->conn_lock);
conn_mgr->conn_data = data;
g_cond_signal (conn_mgr->conn_check);
g_mutex_unlock (conn_mgr->conn_lock);
}
gpointer thread_wait_work (void)
{
gpointer data;
g_mutex_lock (conn_mgr->conn_lock);
while (!conn_mgr->conn_data)
g_cond_wait (conn_mgr->conn_check, conn_mgr->conn_lock);
data = conn_mgr->conn_data;
conn_mgr->conn_data = NULL;
g_mutex_unlock (conn_mgr->conn_lock);
return data;
}
----------------------------=[ End Code ]
where conn_mgr is a global variable which is defined thus:
----------------------------=[ Struct definition ]
struct _connections {
GCond* conn_check; /* The connection condition. */
GMutex* conn_lock; /* The lock for waiting on the connection. */
gpointer conn_data; /* The data about the connection. */
};
----------------------------=[ End Code ]
The code which sends out the work orders looks like this:
----------------------------=[ Signaling Code ]
gboolean thread_give_receive (gpointer socket, gpointer message)
{
work *wrk;
wrk = create_thread_worder ();
wrk->type = receive;
wrk->message = message;
wrk->socket = socket;
thread_give_work (wrk);
return FALSE;
}
----------------------------=[ End Code ]
And the code which calls THAT is:
----------------------------=[ Loop Code ]
for (i = 0; i < m->msgs->len; i++) {
int ind;
printf ("1: Sending to: %p from %p to %p on %d\n", g_ptr_array_index
(m->msgs, i), req, conn, i);
thread_give_receive (conn, g_ptr_array_index (m->msgs, i), mbox);
/* Is a wait needed here? What if another thread comes here too? */
}
----------------------------=[ End Code ]
Any ideas?
-Ben
------------------------------------ |\ _,,,--,,_ ,) ----------
Benjamin Kahn /,`.-'`' -, ;-;;'
(212) 924 - 2220 ext 201 |,4- ) )-,_ ) /\
ben@cybersites.com --------------- '---''(_/--' (_/-' ---------------
Q: Why does it crash?
A: Woah! You should have seen it last week!
-- Linux NETFILTER-HOWTO
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]