首页 > 编程语言 > 详细

在子线程中执行exit()会导致整个进程退出

时间:2020-02-06 18:54:34      阅读:306      评论:0      收藏:0      [点我收藏+]
//
// Created by gxf on 2020/2/6.
//
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>

void printMsg(char *msg);

int main(){
    pthread_t thread;
    pthread_create(&thread, NULL, printMsg, "hello c in thread");

    while (1) {
        printf("in main\n");
        sleep(1);
    }

    return 0;
}

void printMsg(char *msg) {
    int printCount = 10;
    while (printCount) {
        printf("%s\n", msg);
        printCount--;
        sleep(1);
    }
    exit(1);
}

  技术分享图片

 

在子线程中执行exit()会导致整个进程退出

原文:https://www.cnblogs.com/luckygxf/p/12269630.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!