Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pthread_create() returning -1

Status
Not open for further replies.

dcusick

Technical User
Aug 9, 2000
271
US
Anyone know why the pthread_create() would return a -1? I was running my code on a unix emulator, cygwin, and everything ran fine. I moved everything over to a server, and know it's not working. I checked the return values and all my thread creates returned -1. Any ideas?

Doug
 
By the way... Here's my code...

Code:
#include <pthread.h>
#include <thread.h>

#define SIZE 30

pthread_mutex_t mp;
int i = -1;
char *ptr;

void setthread(void *arg) {
  int j = 0;
  i++;

  pthread_mutex_lock(&mp);

  for(j = 0; j<6; j++) {
    printf(&quot;The Value is %d and %d\n&quot;, i, j);
  }

  pthread_mutex_unlock(&mp);
  pthread_exit(0);
}

main() {
  int i = 0;
  int retVal = 0;
  int status;
  pthread_t tid[16];

  pthread_mutex_init(&mp, 0);
  pthread_mutex_unlock(&mp);

  for(i=0; i<5; i++) {
    retVal = pthread_create(&tid[i], 0, (void *)setthread, (void *)i);
  }
  for(i=0; i<5; i++) {
    pthread_join(tid[i], &status);
  }

  printf(&quot;MAIN!\n&quot;);

  pthread_mutex_destroy(&mp);
}
 
Man page of pthread_create does not say anything about the value -1.
Can you please do perror() and tell us the output...
i.e. something like:-

for(i=0; i<5; i++) {
retVal = pthread_create(&tid, 0, (void *)setthread, (void *)i);
perror(&quot;Pthread_create failed&quot;);

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top