歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 在Ubuntu下用Eclipse開發ARM多線程程序

在Ubuntu下用Eclipse開發ARM多線程程序

日期:2017/2/28 15:56:56   编辑:Linux教程

第1步:安裝 Eclipse 開發環境 http://www.linuxidc.com/Linux/2012-02/53964.htm

第2步:配置Eclipse 的ARM開發環境 http://www.linuxidc.com/Linux/2012-02/54007.htm

第3步:新建一個過程,配置好環境

敲入下面的代碼

#include <pthread.h>
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>

void *create(void *arg)
{
while(1)
{
printf("thread is Running ..... ");
sleep(5);
}
}

void *ReaderThread(void *arg)
{
while(1)
{
sleep(4);
printf("Read ID=\r\n");
}
}

int main(int argc, char *argv[])
{
pthread_t tidp;
int rc1,rc2;
rc1=pthread_create(&tidp,NULL,create,NULL);
if(rc1!=0)
{
printf("pthread_create is not created ... \r\n");
return -1;
}

printf("prthread_create is created... \r\n");
rc2=pthread_create(&tidp,NULL,ReaderThread,NULL);
if(rc2!=0)
{
printf("ReaderThread is not created ... \r\n");
return -1;
}

printf("ReaderThread is created... \r\n");
while(1)
{
printf("System is Runing...\r\n");
sleep(1);
}
return 0;
}

編譯看看效果。

Copyright © Linux教程網 All Rights Reserved