samedi 19 janvier 2019

If you have a break inside an if statement that creates a child process in a for loop, does the loop no longer execute?

I am going through a code example in my textbook (dining philosophers problem) and in the main method, right before the return 0; statement, there is the block of code I've included below. This loop is supposed to create the philosophers each as a concurrent forked process. This means that each philosopher executes philosopher(i).

However, since right after the if statement, there follows a break, doesn't that mean only the first philosopher (i = 0) is created?

for (i = 0; i < N - 1; ++i)
    if (fork() == 0) 
        break;
philosopher(i) ;

Aucun commentaire:

Enregistrer un commentaire