在子線程中執行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