- /* actually start the thread */
- arg->listener = xbt_thread_create("listener", listener_function, arg,0/*not joinable*/);
- gras_os_sleep(0); /* TODO: useless? give the listener a chance to initialize even if the main is empty and we cancel it right afterward */
+ /* actually start the thread, and */
+ /* wait for the listener to initialize before we connect to its socket */
+ xbt_mutex_acquire(arg->init_mutex);
+ arg->listener =
+ xbt_thread_create("listener", listener_function, arg,
+ 1 /*joinable */ );
+ xbt_cond_wait(arg->init_cond, arg->init_mutex);
+ xbt_mutex_release(arg->init_mutex);
+ xbt_cond_destroy(arg->init_cond);
+ xbt_mutex_destroy(arg->init_mutex);
+
+ /* Connect the other part of the socket */
+ arg->wakeup_sock_master_side =
+ gras_socket_client(gras_os_myname(),
+ arg->port);