aboutsummaryrefslogtreecommitdiff
path: root/src/io_thread.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-11-27 19:28:21 +0100
committerMax Kellermann <max@duempel.org>2011-11-27 19:28:26 +0100
commit37420c342bf9582a0de32d46f78716e913119400 (patch)
treef8696ad6ec2b69776374aafbfd03c2d762389203 /src/io_thread.c
parentef369c2e2b9334f05ad4fa78c44190bbdb9af3ba (diff)
io_thread: fix race condition during startup
Ensure that the io.thread variable is set before entering the event loop.
Diffstat (limited to 'src/io_thread.c')
-rw-r--r--src/io_thread.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/io_thread.c b/src/io_thread.c
index ffa513d4..2091ecd0 100644
--- a/src/io_thread.c
+++ b/src/io_thread.c
@@ -34,6 +34,7 @@ static struct {
void
io_thread_run(void)
{
+ assert(io_thread_inside());
assert(io.context != NULL);
assert(io.loop != NULL);
@@ -43,6 +44,11 @@ io_thread_run(void)
static gpointer
io_thread_func(G_GNUC_UNUSED gpointer arg)
{
+ /* lock+unlock to synchronize with io_thread_start(), to be
+ sure that io.thread is set */
+ g_mutex_lock(io.mutex);
+ g_mutex_unlock(io.mutex);
+
io_thread_run();
return NULL;
}
@@ -67,7 +73,9 @@ io_thread_start(GError **error_r)
assert(io.loop != NULL);
assert(io.thread == NULL);
+ g_mutex_lock(io.mutex);
io.thread = g_thread_create(io_thread_func, NULL, true, error_r);
+ g_mutex_unlock(io.mutex);
if (io.thread == NULL)
return false;