I’m just playing around with threads to get used to them, so I wanted to make 20 threads that are all alive at the same time, and wrote this program:
static void * threadFunc(void *str)
{
sleep(5);
}
int main (int argc, char * argv[])
{
pthread_t arr[20];
for(int i = 0; i < 20; i++)
{
pthread_create(&arr[i], NULL, threadFunc, (void*)NULL);
cout << "i=" << i << "\ntotal threads=" << pthread_is_threaded_np() << "\n";
}
}
But it keeps saying total number of threads is 1. What am I missing here?
What do you think
pthread_is_threaded_np()does? Here’s a hint: it’s not what you want.