Fix data race on task refcount in psync_task_free (#344)
Acquire mutex before reading tm->refcnt to prevent race with psync_task_dec_refcnt(). Fixes ThreadSanitizer warning. Fixes #332 Co-authored-by: Levi Neely <lkn@darkstar.example.net>
This commit is contained in:
parent
ede53b6b89
commit
9c721bde00
|
|
@ -1181,12 +1181,13 @@ void *psync_task_papi_result(psync_task_manager_t tm, int id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void psync_task_free(psync_task_manager_t tm) {
|
void psync_task_free(psync_task_manager_t tm) {
|
||||||
|
int refcnt, i;
|
||||||
|
pthread_mutex_lock(&tm->mutex);
|
||||||
if (tm->refcnt == 1) {
|
if (tm->refcnt == 1) {
|
||||||
|
pthread_mutex_unlock(&tm->mutex);
|
||||||
psync_task_destroy(tm);
|
psync_task_destroy(tm);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int refcnt, i;
|
|
||||||
pthread_mutex_lock(&tm->mutex);
|
|
||||||
tm->waitfor = PSYNC_WAIT_FREED;
|
tm->waitfor = PSYNC_WAIT_FREED;
|
||||||
for (i = 0; i < tm->taskcnt; i++)
|
for (i = 0; i < tm->taskcnt; i++)
|
||||||
if (tm->tasks[i].status == PSYNC_TASK_STATUS_READY) {
|
if (tm->tasks[i].status == PSYNC_TASK_STATUS_READY) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue