⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainthreadexits.c

📁 cygwin, 著名的在win32下模拟unix操作系统的东东
💻 C
字号:
#include <stdio.h>#include <unistd.h>#include <pthread.h>static void * Thread (void *);static pthread_t main_thread;static pthread_t secondThread;static int result = 2;int main(void){  main_thread = pthread_self ();  if (pthread_create (&secondThread, NULL, Thread, NULL))      exit (1);  sleep (5);  pthread_exit (&result);  /* If pthread_exit doesm't (which would be a bug) then we do */  return 1;}static void * Thread (void *not_used){  void *myresult;  /* We should be able to join this */  if (pthread_join (main_thread, &myresult))      exit (1);  if (*(int *)myresult != 2)      exit (1);  exit (0);}/*This valid code doesn't work at all. The mainthread object in MTinterfaceis not properly initialized, the cancel_event is NULL and the win32_obj_idis NULL because myself->hProcess is NULL when MTinterface is initialized(and i don't think that a process handle can be used as thread handle).Even if the handles would be valid the pthread_join call would try todelete a thread object that is created static which would result in acorrupted heap.Concept test Contributed by Thomas Pfaff <tpfaff@gmx.net>Scriptable test by Robert Collins <rbtcollins@hotmail.com>*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -