exe

来源:互联网 发布:淘宝不能修改宝贝详情 编辑:程序博客网 时间:2024/04/28 15:14
#include <stdio.h>
#include <pthread.h>

void *myThread1(void)
{
    int i;
    for (i=0; i<100; i++)
    {
        printf("This is the 1st pthread,created by zieckey.\n");
        sleep(1);//Let this thread to sleep 1 second,and then continue to run
    }
}

void *myThread2(void)
{
    int i;
    for (i=0; i<100; i++)
    {
        printf("This is the 2st pthread,created by zieckey.\n");
        sleep(1);
    }
}

int main()
{
    int i=0, ret=0;
    pthread_t id1,id2;
    
    /*创建线程1*/
    ret = pthread_create(&id1, NULL, (void*)myThread1, NULL);
    if (ret)
    {
        printf("Create pthread error!\n");
        return 1;
    }
    
    /*创建线程2*/
    ret = pthread_create(&id2, NULL, (void*)myThread2, NULL);
     if (ret)
    {
        printf("Create pthread error!\n");
        return 1;
    }
    
   // pthread_join(id1, NULL);
    //pthread_join(id2, NULL);
    
    return 0;
}
0 0
原创粉丝点击