diff --git a/LibOS/shim/src/ipc/shim_ipc_helper.c b/LibOS/shim/src/ipc/shim_ipc_helper.c index a384913c..72c65f3c 100644 --- a/LibOS/shim/src/ipc/shim_ipc_helper.c +++ b/LibOS/shim/src/ipc/shim_ipc_helper.c @@ -849,8 +849,13 @@ static int create_ipc_helper(void) { * problematic for the thread itself to release its own resources e.g. stack). */ struct shim_thread* terminate_ipc_helper(void) { - if (ipc_helper_state != HELPER_ALIVE) + /* First check if thread is alive. */ + lock(&ipc_helper_lock); + if (ipc_helper_state != HELPER_ALIVE) { + unlock(&ipc_helper_lock); return NULL; + } + unlock(&ipc_helper_lock); /* NOTE: Graphene doesn't have an abstraction of a queue of pending signals * between communicating processes (instead all communication is done over @@ -867,6 +872,11 @@ struct shim_thread* terminate_ipc_helper(void) { DkThreadDelayExecution(500); lock(&ipc_helper_lock); + if (ipc_helper_state != HELPER_ALIVE) { + unlock(&ipc_helper_lock); + return NULL; + } + struct shim_thread* ret = ipc_helper_thread; if (ret) get_thread(ret); diff --git a/LibOS/shim/src/shim_async.c b/LibOS/shim/src/shim_async.c index 2e79d7af..08dfcf02 100644 --- a/LibOS/shim/src/shim_async.c +++ b/LibOS/shim/src/shim_async.c @@ -114,8 +114,10 @@ int64_t install_async_event(PAL_HANDLE object, uint64_t time, if (async_helper_state == HELPER_NOTALIVE) { int ret = create_async_helper(); - if (ret < 0) + if (ret < 0) { + unlock(&async_helper_lock); return ret; + } } unlock(&async_helper_lock); @@ -306,10 +308,13 @@ static int create_async_helper(void) { * problematic for the thread itself to release its own resources e.g. stack). */ struct shim_thread* terminate_async_helper(void) { - if (async_helper_state != HELPER_ALIVE) - return NULL; - lock(&async_helper_lock); + + if (async_helper_state != HELPER_ALIVE) { + unlock(&async_helper_lock); + return NULL; + } + struct shim_thread* ret = async_helper_thread; if (ret) get_thread(ret);