I wrote the following code:
#include<iostream>
#include<pthread.h>
using namespace std;
void* func(void *i)
{
cout<<"in func "<<endl;
}
int main()
{
pthread_t threads[5];
for(int i=0;i<5;i++)
{
pthread_create(&threads[i], NULL, func, (void*)i);
cout<<"next for loop"<<endl;
}
pthread_exit(NULL);
return 0;
}
The output was:
From the output it seems that the endl line changing property after first display of 'next for loop' gets delayed and endl of 'next for loop' and 'in func' are executed one after the other. This happened everytime i ran the program. Can you tell me the reason for this delay?