Is one line of the fprintf command thread safe?

I am using openmp and my program is as follows:

\#pragma omp parallel for

for(x = 0, y = 0, x < 5, x++, y++)

     function(x, y, fp);

void function(int x , int y, FILE* fp);
{
   fprintf(fp, "(%d, %d)\n", x y);
}

I want the contents of the file as

(0, 0)
(2, 2)
(1, 1)
(3, 3)
(4, 4)

The order does not matter, but the x, y coordinates must be in order, that is, the program should not generate something like (2, 3). Is this behavior always guaranteed? I am using gcc compiler in linux.

+5
source share
1 answer

You have incompatible assumptions in your question. OpenMp is not part of the C standard, so the C specification cannot say anything about the OpenMp stream model and provide anything about the security of its functions. Until recently, C did not even have a stream model.

C11 , , -, :

, , . . : .

, , C11, , , C- POSIX- . , OpenMp, , , , C11.

+3

All Articles