我开始在linux上进行pthread编程,在第一个程序中我完全搞糊涂了.以下是我正在运行的程序
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *print_message_function( void *ptr );
int main(){
pthread_t thread1, thread2;
char *message1 = "Thread 1";
char *message2 = "Thread 2";
int iret1, iret2;
/* Create independent threads each of which will execute function */
iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1);
iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);
/* Wait till threads are complete before main continues. Unless we */
/* wait we run the risk of executing an exit which …Run Code Online (Sandbox Code Playgroud) 我有一个C程序,我使用pthread.
我希望新创建的线程在创建后立即运行.
这背后的原因是我的线程有初始化代码来设置信号处理程序,我必须确保处理程序准备就绪,然后我的主线程发送一些信号.
我试着做pthread_yield只是我后pthread_create,但没有成功.
我怀疑它有所不同,但我在x86_64上运行Linux 3.6.
谢谢