[1.7] pthread_create block
Thomas Stalder
cygwinml@gmail.com
Tue Jun 2 09:10:00 GMT 2009
Hello,
Sometimes pthread_create block and never return.
I have made a simple program (test.c) to reproduce the problem.
> gcc test.c -lpthread -o test
> ./test
thread id=1
thread id=2
thread id=3
thread id=4
........
thread id=3736
Sometimes pthread_create block after creating arround 10 threads,
sometimes after creating arround 10000 threads or more.
The test program work well under linux.
--
Thomas
-------------- next part --------------
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
static pthread_mutex_t my_mutex = PTHREAD_MUTEX_INITIALIZER;
int nb_thread=0;
void *thread_func(void *parm)
{
int id;
pthread_mutex_lock(&my_mutex);
nb_thread++;
id = nb_thread;
pthread_mutex_unlock(&my_mutex);
printf("thread id=%d\n", id);
pthread_exit(0);
return NULL;
}
int main(void)
{
while(1)
{
int err = 0;
pthread_attr_t attr;
pthread_t thread_id;
/* Initialize the attribute */
err = pthread_attr_init(&attr);
if (err)
{
printf("pthread_attr_init err=%d\n", err);
}
err = pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
if (err)
{
printf("pthread_attr_setinheritsched error\n");
}
err = pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
if (err)
{
printf("pthread_attr_setdetachstate error\n");
}
/* Create the thread with our attribute */
// printf("before pthread_create\n");
err = pthread_create(&thread_id, &attr, thread_func, NULL);
if (err)
{
printf("pthread_create error\n");
}
// printf("after pthread_create\n");
pthread_attr_destroy(&attr);
}
}
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list