Skip to content

Commit

Permalink
cbus: fix inconsistency in endpoint creation
Browse files Browse the repository at this point in the history
The notification of wait variable shall be done under
a bound mutex locked. Otherwise the results are not
guaranteed (see pthread manuals).

Thus when we create a new endpoint via cbus_endpoint_create
and there is an other thread which sleeps inside cpipe_create
we should notify the sleeper under cbus.mutex.

Fixes #4806

Reported-by: Alexander Turenko <alexander.turenko@tarantool.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
(cherry picked from commit d6d69c9)
  • Loading branch information
cyrillos authored and kyukhin committed Apr 24, 2020
1 parent 018cf41 commit 3dea0c8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/core/cbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ cbus_endpoint_create(struct cbus_endpoint *endpoint, const char *name,
ev_async_start(endpoint->consumer, &endpoint->async);

rlist_add_tail(&cbus.endpoints, &endpoint->in_cbus);
tt_pthread_mutex_unlock(&cbus.mutex);
/*
* Alert all waiting producers.
*
Expand All @@ -243,6 +242,7 @@ cbus_endpoint_create(struct cbus_endpoint *endpoint, const char *name,
* blocked on cond.
*/
tt_pthread_cond_broadcast(&cbus.cond);
tt_pthread_mutex_unlock(&cbus.mutex);
return 0;
}

Expand Down

0 comments on commit 3dea0c8

Please sign in to comment.