编程语言
首页 > 编程语言> > 线程例程执行到一般就不执行了/程序结束了

线程例程执行到一般就不执行了/程序结束了

作者:互联网

void *routine1(void *arg)
{
    printf("%d",__LINE__);

    //初始化播放链表
    //头节点
    P_Node head = NewNode(NULL);
    printf("%d",__LINE__);
    int img_num = DepthTheCatalog( head , ".jpg"  , "/root/pic"  ) ;
    img_num += DepthTheCatalog( head , ".bmp"  , "/root/pic"  ) ;
    printf("查找文件结束,一共有%d个图像文件\n",img_num);
    //遍历链表(显示播放图片播放列表)
    DisplayList(head);

    //循环播放图片。链表,显示坐标。
    AutoDisplay(head,400,0);
}

int main(int argc, char const *argv[])
{
    //打开LCD设备
    lcd_open();
    printf("%d\n",__LINE__);

    //创建线程-图片显示(进入例程,自动循环)tid1
    pthread_t tid1;
    pthread_create(&tid1,NULL,routine1,NULL);
    printf("%d\n",__LINE__);

    //关闭LCD
    // lcd_close();
    return 0;
}

原代码如上。输出了tid1线程例程中第一行的printf就结束了。

解决:

主程序在线程执行完毕之前先一步执行完毕结束程序了,主进程一旦结束,其进程中的线程也会一并结束。

在主程序后加上while(1)

 

标签:__,head,tid1,例程,线程,printf,LINE,执行
来源: https://www.cnblogs.com/popo9nite/p/16397124.html