Re: [問題] 一個ThreadX的問題

作者: descent (「雄辯是銀,沉默是金」)   2014-09-25 19:25:35
我修改了 http://sp1.wikidot.com/pthread 成類似你的寫法。
在 linux 上可以正常執行 printf("Mary\n");
gcc p.c -pthread
#include <pthread.h> // 引用 pthread 函式庫
#include <stdio.h>
void *print_george(void *argu) { // 每隔一秒鐘印出一次 George 的函數
while (1) {
//printf("George\n");
//sleep(1);
}
return NULL;
}
void *print_mary(void *argu) { // 每隔一秒鐘印出一次 Mary 的函數
while (1) {
printf("Mary\n");
//sleep(2);
}
return NULL;
}
int main() { // 主程式開始
pthread_t thread1, thread2; // 宣告兩個執行緒
pthread_create(&thread1, NULL, &print_george, NULL); // 執行緒
print_george
pthread_create(&thread2, NULL, &print_mary, NULL); // 執行緒 print_mary
while (1) { // 主程式每隔一秒鐘
//printf("
作者: askacis (ASKA)   2014-09-26 02:04:00
你跑在userspace,kernelspace while(1)又不讓渡會很慘XD

Links booklink

Contact Us: admin [ a t ] ucptt.com