Simple posix thread

Need help with C, C++, perl, python, etc?

Simple posix thread

Postby Jay » 2007-04-14 23:44

Can some please help me - I have a very simple thread program below - in which I have a simple printf statement. The funny thing is it does not print the statement "Running SERVER thread: " that is inside the thread funciton?

It only output - "Exiting main" Why does it not print "Running SERVER thread: "

Your help is very much appreciated:-)

Thanks!

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#include <pthread.h>
#include <stdio.h>
#include <string.h>

void *serverthread(void * parm);

main (int argc, char *argv[])
{
int ret;
pthread_t tid; /* variable to hold thread ID */

ret = pthread_create(&tid, NULL, serverthread, NULL );

if( ret != 0 )
{
printf("Error in creating thread \n");
}

printf("Exiting main \n");

return 0;

}

void *serverthread(void * parm)
{

printf("Running SERVER thread: ");

pthread_exit(0);
}
Jay
 

threads

Postby norm » 2007-04-15 02:48

Here is an example similar to yours. Note the comment statements.

Norm
norm
 


Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests

fashionable