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


//
// 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);
}

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM