5574l2 Listing 2. Windows Threads Version of Gothello main() #ifdef _WIN32 /* Windows theads version of Gothello main() */ DWORD WINAPI child_thread(LPVOID data) { do_child(to_child[0], to_parent[1]); return 1; } DWORD WINAPI read_thread(LPVOID data) { gpointer gdata; int source; GdkInputCondition condition; gdata=0; source=-1; condition=-1; for(;;) { read_from_child(gdata,source,condition); printf("read_from_child\n"); } return 1; } int FakeFork(void* data) { DWORD id=0; HANDLE h=CreateThread(0,0,child_thread,data,0,&id); if(!h) { return 0; } h=CreateThread(0,0,read_thread,data,0,&id); return 0!=h; } int main (int argc, char** argv) { /* parent: */ if (pipe(to_child) == -1) { panic_err("can't create pipe"); } if (pipe(to_parent) == -1) { panic_err("can't create pipe"); } /* init gtk and most everything else */ init_all(argc, argv); if(!FakeFork(0)) { printf("FakeFork failed\n"); return 1; } gtk_main(); return 0; } #else /* original Gothello Linux fork code below */ int main (int argc, char** argv) { /* create pipes and fork */ if (pipe(to_child) == -1) panic_err("can't create pipe"); if (pipe(to_parent) == -1) panic_err("can't create pipe"); switch (fork()) { case -1: panic_err("can't fork"); break; case 0: /* child */ close(to_child[1]); close(to_parent[0]); do_child(to_child[0], to_parent[1]); /* safety measure, in case do_child should return due to some bug */ _exit(0); break; default: /* parent */ close(to_child[0]); close(to_parent[1]); break; } /* init gtk and most everything else */ init_all(argc, argv); gtk_main(); return 0; } #endif