diff --git a/lib/libthr/thread/thr_pshared.c b/lib/libthr/thread/thr_pshared.c --- a/lib/libthr/thread/thr_pshared.c +++ b/lib/libthr/thread/thr_pshared.c @@ -217,15 +217,23 @@ __thr_pshared_offpage(void *key, int doalloc) { struct pthread *curthread; - void *res; + void *res, *val; int fd, ins_done; curthread = _get_curthread(); - pshared_rlock(curthread); - res = pshared_lookup(key); - pshared_unlock(curthread); - if (res != NULL) - return (res); + if (doalloc) { + pshared_wlock(curthread); + val = pshared_remove(key); + pshared_unlock(curthread); + pshared_clean(key, val); + res = NULL; + } else { + pshared_rlock(curthread); + res = pshared_lookup(key); + pshared_unlock(curthread); + if (res != NULL) + return (res); + } fd = _umtx_op(NULL, UMTX_OP_SHM, doalloc ? UMTX_SHM_CREAT : UMTX_SHM_LOOKUP, key, NULL); if (fd == -1)