[gnet] timing problem with threads



Hello!

I wrote a threaded programm:
Thread_1: main_loop
Thread_2: something like an echo prog ... usefull as test programm for a specialized communication module.

The programm segfaults with a strage behaviour:
I found that "gnet_conn_write" puts the correct pointer to the "write_queue" but "conn_write_async_cb" gets "write_queue == NULL"

I could not reproduce the behaviour using the examples (echo*-gconnect)
... The client was modified to also return each string it receives ...
but, those programms are not threaded.

At last ... The prog does not segfault, when running in the "virtual mashine" of gdb or valgrind. Therefore I suppose that it is a timing problem, but I may be completely wrong.

Your ideas are greatly appreciated. I ran out of those.

Jean.

see conn.c lines 1097 ... 1142
--------------------------------------------------------
void
gnet_conn_write (GConn* conn, gchar* buffer, gint length)
{
  Write* write;

  g_return_if_fail (conn);
  g_return_if_fail (conn->func);

  /* Add to queue */
  write = g_new0 (Write, 1);
  write->buffer = g_memdup (buffer, length);
  write->length = length;
  conn->write_queue = g_list_append (conn->write_queue, write);
//added g_critical("in %p",write);
  conn_check_write_queue (conn);
}


static void
conn_check_write_queue (GConn* conn)
{
  /* Ignore if we are unconnected or there is no writes */
  if (!IS_CONNECTED(conn) || !conn->write_queue)
    return;

  /* Ignore if we are already watching OUT */
  if (IS_WATCHING(conn, G_IO_OUT))
    return;

  /* Watch for write */
  ADD_WATCH (conn, G_IO_OUT);
}


static void
conn_write_async_cb (GConn* conn)
{
  Write*     write;
  GIOError   error;
  guint      bytes_to_write;
  gchar*     buffer_start;
  guint      bytes_written;
  GConnEvent event = {GNET_CONN_ERROR, NULL, 0};

  g_assert(conn->write_queue);
  write = (Write*) conn->write_queue->data;
  g_return_if_fail (write != NULL);




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