pthread
库创建线程。,``c,#include,void* thread_function(void* arg) {, // 线程代码,},int main() {, pthread_t thread;, pthread_create(&thread, NULL, thread_function, NULL);, pthread_join(thread, NULL);, return 0;,},
``pthread
库创建线程。,``c,#include,void* thread_function(void* arg) {, // 线程代码,},int main() {, pthread_t thread;, pthread_create(&thread, NULL, thread_function, NULL);, pthread_join(thread, NULL);, return 0;,},
``c,#include,#include,#include,,void *print_message_function(void *ptr) {, char *message;, message = (char *) ptr;, printf("%s ,", message);, return NULL;,},,int main() {, pthread_t thread1, thread2;, char *message1 = "Thread 1";, char *message2 = "Thread 2";, int iret1, iret2;,, iret1 = pthread_create(&thread1, NULL, print_message_function, (void*) message1);, iret2 = pthread_create(&thread2, NULL, print_message_function, (void*) message2);,, pthread_join(thread1, NULL);, pthread_join(thread2, NULL);,, printf("Thread 1 returns: %d,", iret1);, printf("Thread 2 returns: %d,", iret2);,, exit(0);,},
``Powered By Z-BlogPHP 1.7.3