Click to See Complete Forum and Search --> : pthread_create Function


divakarp
February 21st, 2003, 05:07 PM
I trying to create multi thread programming in C.

I am getting ENOSYS error from pthread_create function. I would appreciate if someone can assit me. I am calling function thread_loop twice. But it is executing only once. Gettint error from pthread_create function. Thanks.


#include <pthread.h>
#include <errno.h>


void* thread_loop(void* data)
{

int i = 0;
long j = 0;

printf("Inside the function \n");

for (i = 0 ; i<5; i++)
{
for (j=0; j<900 ; j++);
printf("I value %d \n", i);
}

}

void main(int argc, char *argv[] )
{


int i = 1;

pthread_t thread1 ;

int ret ;


ret = pthread_create(&thread1, NULL, thread_loop, (void*) &i) ;


switch (ret)
{

case 0 : printf("pthread_create function Success \n"); break ;

case EAGAIN : printf("Error : No more processes \n"); break ;

case ENOSYS : printf("Error : Function not implemented \n"); break ;

case EINVAL : printf("Error : Invalid Argument \n"); break ;

case EPERM : printf("Error : Not super-user \n"); break ;

default : printf("Other error from pthread_create \n"); break ;

}

printf("End Of Main %d \n ", ret);

thread_loop(&i);

}

mikledet
February 21st, 2003, 06:24 PM
Aside from not linking with pthread library - but i don't know if you should get an error while compiling or linking- (might be that you dont - because of #define in h files...), any way, are you sure you get only one instrance of the function?
Did you go thorugh the output to see you dont have duplicates?
You could very easily mistake it - since both would be running at the same time...
Take a good look at your print out - and look for doubles...
If you have two of the same lines (not neseceraly at the same place) - it means all is working well.

KevinHall
February 21st, 2003, 06:29 PM
What OS are you using?

divakarp
February 24th, 2003, 09:27 AM
I am using unix OS.

I am pretty sure it is not even entering the function.

KevinHall
February 24th, 2003, 10:10 AM
There are a variety of unix platforms as well as different unix compilers. The error message suggests that the function is not implemented. I would consult the compiler manual (or man pages) as well as the OS documentation to see what it can support.

- Kevin