亚洲精品中文字幕无乱码_久久亚洲精品无码AV大片_最新国产免费Av网址_国产精品3级片

C語(yǔ)言

c語(yǔ)言線(xiàn)程終止練習(xí)示例

時(shí)間:2024-06-03 13:12:42 C語(yǔ)言 我要投稿
  • 相關(guān)推薦

c語(yǔ)言線(xiàn)程終止練習(xí)示例

  c語(yǔ)言線(xiàn)程

  代碼如下:

  #include

  #include

  #include

  void *t1(void *args)

  {

  return (void *) 0;

  }

  void *t2(void *args)

  {

  printf("thread 2 param[args] = %dn", args);

  pthread_exit((void *) 3);

  }

  void *t3(void *args) {

  while(1)

  {

  printf("thread 3 is workingn");

  sleep(1);

  }

  }

  int main(int argc, char *argv[])

  {

  pthread_t thread;

  int err;

  void *status;

  printf("creating thread 1n");

  err = pthread_create(&thread, NULL, t1, NULL);

  if(err)

  {

  printf("Can not created thread 1n");

  exit(-1);

  }

  pthread_join(thread, &status);

  printf("thread 1 exit return code %dnn", status);

  printf("creating thread 2n");

  err = pthread_create(&thread, NULL, t2, (void *) 9);

  if(err)

  {

  printf("Can not created thread 2n");

  exit(-2);

  }

  pthread_join(thread, &status);

  printf("thread 2 exit return code %dnn", status);

  printf("creating thread 3n");

  err = pthread_create(&thread, NULL, t3, NULL);

  if(err)

  {

  printf("Can not created thread 3n");

  exit(-3);

  }

  sleep(10);

  pthread_cancel(thread);

  pthread_join(thread, &status);

  printf("thread 3 exit return code %dn", status);

  return 1;

  }

【c語(yǔ)言線(xiàn)程終止練習(xí)示例】相關(guān)文章:

C語(yǔ)言模擬試題練習(xí)12-09

C語(yǔ)言考點(diǎn)題型練習(xí)03-28

C語(yǔ)言高分預(yù)測(cè)題練習(xí)12-12

C語(yǔ)言精選模擬練習(xí)題03-28

C語(yǔ)言考前練習(xí)試題及答案03-28

C語(yǔ)言考前模擬練習(xí)題03-27

C語(yǔ)言程序改錯(cuò)題練習(xí)03-27

C語(yǔ)言考試模擬練習(xí)題03-28

C語(yǔ)言新增無(wú)紙化真考題練習(xí)03-28