Re: [gnet] timing problem with threads



as follow up to my own request

To illustrate the problem with "gnet_conn_write", here is a patch to the echoclient-gconn.c file that comes with the gnet2 examples.

I simply added a client function as thread. It sends (or shall) a string 3 times to the echo server. It segfaults when writing the second string. What went wrong? Again, it does it, running with valgrind :-|

Greetings,

JeanM.


34a35,54
> GMainLoop* main_loop;
> 
> 
> gpointer client(gpointer ptr){
> 	GConn* conn = ptr;
> 	GString *str;
> 	guint i;
> 	
> 	g_main_loop_ref(main_loop);
> 	while (FALSE == g_main_loop_is_running(main_loop));
> 	
> 	str = g_string_new("Hello World,\nGreetings from jeanm\n");
> 	
> 	for (i = 0; i < 3; ++i){
> 		gnet_conn_write (conn, str->str, 1 + str->len);
> 		g_usleep(1000000);
> 	}
> 	g_main_loop_unref(main_loop);
> 	return NULL;
> }
42d61
<   GMainLoop* main_loop;
73a93,95
>   /* start the producer */
>   g_thread_create(client,conn,TRUE,NULL);
> 	
178a201
> 	fprintf (stderr, "Connection close\n");


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