pthread_join function introduction: span> strong> p>
The function pthread_join is used to wait for the end of a thread, synchronous operation between threads. Header file: #include < pthread.h>
Int pthread_join(pthread_t thread, void **retval);
description: the pthread_join() function blocks and waits for the thread specified by the thread to terminate. When the function returns, the resource being held by the waiting thread is reclaimed. If the thread has ended, the function returns immediately. And the thread specified must be Joinable.
argument: thread: thread identifier, or thread ID, identifies a unique thread. Retval: User-defined pointer to store the return value of the waiting thread.
return value: 0 for success. Failed and an error number is returned.
.
1, example code:
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
void *thread_function(void *arg) {
int i;
for ( i=0; i<8; i++) {
printf("Thread working...! %d \n",i);
sleep(1);
}
return NULL;
}
int main(void) {
pthread_t mythread;
if ( pthread_create( &mythread, NULL, thread_function, NULL) ) {
printf("error creating thread.");
abort();
}
if ( pthread_join ( mythread, NULL ) ) {
printf("error join thread.");
abort();
}
printf("thread done! \n");
exit(0);
}
.
O
0 GCC thread.c-o thread.o-pthread
.
span> ./thread. O command execution.
span> 4, the running effect is as follows: span> span> span>
span> span> span>
Read More:
- The reason and solution of the error of join function: sequence item 0: expected STR instance, int found
- undefined reference to `pthread_create’ collect2: ld returned 1 exit status
- Brief introduction of cmake generating all in vs Project_ BUILD、INSTALL、ZERO_ Check function!!
- RT-thread assertion failed at function:rt_application_init
- Introduction to JIRA introduction to HP ALM
- Vs2017 reported an error. Pthread. H header file cannot be opened and cannot be found
- Brief introduction of Linux MMAP and solution of bus error
- Error:join network can not connect to Zerotier service
- Brief introduction of idea Lombok and solutions for reporting red and wrong
- Introduction to VTK
- /usr/include/boost/type_traits/detail/has_binary_operator.hp:50: Parse error at “BOOST_JOIN”
- Elasticsearch cluster cannot be started. The following prompt fails to send join request to master appears
- Introduction of Hadoop HDFS and the use of basic client commands
- Introduction to the principle of Mali tile based rendering
- [depth concept] · introduction of EER (equal error rate)
- Introduction to total phase data center
- GoogleIO 2013 Android fast networking framework Volley introduction
- Golang timer function executes a function every few minutes
- Error running ‘application’: command line is too long. Short command line for application
- Python – get the information of calling function from called function