Skip to content

Potential error(e.g., deadlock, ill peformance) due to the unreleased lock threadLocks[myCPU] #416

@jenny-cheung

Description

@jenny-cheung

Hi, developers, thank you for your checking. The lock threadLocks[myCPU] may not be correctly released if the results->state != MARKER_STATE_START satisfies and the control flow goes to the branch listed below. Finally, the method returns with the unreleased lock. The fix is to insert pthread_mutex_unlock(&threadLocks[myCPU]); before returning.

pthread_mutex_lock(&threadLocks[myCPU]);

if (results->state != MARKER_STATE_START)

return -EFAULT;

int
likwid_markerStopRegion(const char* regionTag)
{
    ...;
    if (use_locks == 1)
    {
        pthread_mutex_lock(&threadLocks[myCPU]);
    }

    cpu_id = hashTable_get(tag, &results);
    thread_id = getThreadID(cpu_id);
    if (results->state != MARKER_STATE_START)
    {
        fprintf(stderr, "WARN: Stopping an unknown/not-started region %s\n", regionTag);
        return -EFAULT;
    }
   ...;
    results->state = MARKER_STATE_STOP;
    if (use_locks == 1)
    {
        pthread_mutex_unlock(&threadLocks[myCPU]);
    }
    return 0;
}

Best,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions