PlayBook NDK上的多线程编程

本文介绍了一个简单的PlayBook NDK环境下多线程编程示例。通过调用pthread_create方法创建新线程,并演示了主线程与子线程的并发执行过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

测试了PlayBook NDK上编写的控制台程序后,马上想进一步测试的就是PlayBook NDK上的多线程编程。经过测试很开心地发现PlayBook NDK上进行多线程编程和之前的QNX编程环境是相同的。也就是说在程序中可以简单地调用pthread_create方法实现线程的创建。

如此简单的事情就不再啰嗦了,直接上代码,供各位参考:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

void new_Thread() {

	fprintf(stderr, "..............in the Thread\n");

	int pthread_t = pthread_self();

	int i = 0;

	for (i = 0; i < 10; i++) {

		fprintf(stderr, "......%d........in the Thread %d \n", i, pthread_t);
		sleep(1);
	}

}

int main(int argc, char *argv[]) {

	fprintf(stderr, "starting my thread test...\n");

	pthread_create(NULL, NULL, &new_Thread, NULL);

	int i = 0;
	for (i = 0; i < 20; i++) {
		fprintf(stderr, "in the main loop! %d \n", i);
		sleep(1);
	}

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值