相关疑难解决方法(0)

在Linux上执行pthread

我开始在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 linux pthreads

3
推荐指数
1
解决办法
5652
查看次数

Pthread在创建后立即运行一个线程

我有一个C程序,我使用pthread.

我希望新创建的线程在创建后立即运行.

这背后的原因是我的线程有初始化代码来设置信号处理程序,我必须确保处理程序准备就绪,然后我的主线程发送一些信号.

我试着做pthread_yield只是我后pthread_create,但没有成功.

我怀疑它有所不同,但我在x86_64上运行Linux 3.6.

谢谢

c linux multithreading pthreads

1
推荐指数
2
解决办法
2872
查看次数

标签 统计

c ×2

linux ×2

pthreads ×2

multithreading ×1