If I make 2 detached threads which count to 10 and write the message on STDOUT, everything is OK. But, if I put sleep() into the loop of the thread function (line (1)), then only the first thread is executed and the loop within the thread for just one time. Why?
Also, everything works fine if I use joinable thread with pthread_join(), then there's no problem with sleep(). So, why detached thread makes the problem?
Thread start function, counts to 10 and exits.
void* f(void* arg)
char* param = (char*)arg;
for (i = 1; i <= 10; i++)
printf("\n%s %d", param, i);
sleep(1);/* (1) */
char arg1 = "thread1";
char arg2 = "thread2";
pthread_create(&th1, &attr1, &f, arg1);
pthread_create(&th2, &attr2, &f, arg2);
Thanks in advance.