//
// 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()会导致整个进程退出

 

相关文章:

  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-11-28
  • 2021-12-03
猜你喜欢
  • 2021-10-04
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
相关资源
相似解决方案