Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Simple posix thread

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
Jay

Simple posix thread

#1 Post by Jay »

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);
}

norm

threads

#2 Post by norm »

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

Norm

Post Reply