Unsynchronized use of file system operations

Unsynchronized use of file system operations

The API functions that access the file system such as fopen, mkdir, and chmod are not thread-safe and therefore should not be used in a multi-threaded region. This can cause different execution results in parallel and sequential mode.

ID

Observation

Description

1

Call site

The place the unsafe function was called

Examples


#include <stdio.h>

int main(int argc, char **argv)
{
    int i;
    FILE * fp;

#pragma omp parallel for lastprivate(fp)
    for (i = 0; i < 6; i++) {
        fp = fopen("my_file.txt", "r");
    }
    fclose(fp);
    return 0;
}
        

Copyright © 2010, Intel Corporation. All rights reserved.