|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
Socket Server cultural issues -- the POSIX Thread Debugging with the following errors occur when the server
[color=red][root@BillingServer Unix]# gcc -o PRG6_5 PRG6_5.c
/tmp/cc37bHFj.o (. Text+0x16e) : In function `main ':
: Undefined reference to `pthread_create '
Collect2 : ld returned one exit status[/color]
Now this is certainly part of the program code issues
[code]struct ARG arg;
Arg.connfd = connectfd;
Memcpy ((void *) &arg.client, &client, sizeof (client));
If (pthread_create (&thread, NULL, start_routine, (void *) & arg))
{
Perror ( "Pthread_create () error");
Exit (1);
}[/code]
Posix-thread programming is the first contact, it was not clear hope that the master guiding instructions
Following is the official website gives some hints : ibm
POSIX through pthread_create () function to create thread, the API defined as follows :
Int pthread_create (pthread_t * thread, pthread_attr_t * attr.
Void * (*start_routine) (void *), void * arg)
And the fork () call to create a process in different ways, pthread_create () does not have the main thread to create the thread (Call pthread_create () thread), the implementation of the same sequence, but to make it operational start_routine (arg) function. Return to the thread ID thread creation, thread attr is the attribute am creating threads (see below). Pthread_create () thread creation, said the success of the return value. Although it is void * arg types of variables, but it can also pass parameters as arbitrary types of start_routine () function; Meanwhile, start_routine () * to return a void return type of value, and this value can be returned to other types, by pthread_join () access. |
Socket Server cultural issues -- the POSIX Thread You have no Treasury! |
Socket Server cultural issues -- the POSIX Thread #include "Pthread.h>;
Translated, it needs to add the following options :
-lpthread |
| |