patcat88 has asked for the wisdom of the Perl Monks concerning the following question:
#define WIN32_LEAN_AND_MEAN #include <windows.h> #include "EXTERN.h" #include "perl.h" #include "XSUB.h" DWORD WINAPI ThreadFunc ( HANDLE * eventPtr) { DWORD retval; retval = WaitForSingleObject(*eventPtr, 10000); if(retval == WAIT_OBJECT_0) { printf("wait suceeded"); } else if(retval == WAIT_TIMEOUT){ //crash gracefully printf("Timeout, now exiting"); exit(1);} } //crash gracefully else {printf("WaitForSingleObject failed"); exit(1);} if(!CloseHandle(*eventPtr) { //crash gracefully printf("CloseHandle failed error is %u\n", GetLastError()); +exit(1); } free(eventPtr); return 1; } MODULE = MyMod PACKAGE = MyMod PROTOTYPES: DISABLE DWORD perlfunc () PREINIT: HANDLE * evtHandlePtr; HANDLE thHandle; CODE: evtHandlePtr = malloc(sizeof(HANDLE)); *evtHandlePtr = CreateEvent(NULL, TRUE, FALSE, NULL); if(*evtHandlePtr == NULL){printf("CreateEvent failed error is %u\n",Ge +tLastError()); exit(1);} thHandle = CreateThread(NULL, 1024, ThreadFunc, evtHandlePtr, 0, NULL) +; if(thHandle == NULL){printf("CreateThread failed error is %u\n",GetLas +tError()); exit(1);} else { if (!CloseHandle(thHandle)) {printf("CloseHandle on thread handle failed error is %u\n",GetLa +stError()); exit(1);} } //lets time out, so no SetEvent RETVAL = 1; OUTPUT: RETVAL
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XS replacing my c library, not compatible with OS threads
by BrowserUk (Patriarch) on Nov 30, 2010 at 19:26 UTC | |
|
Re: XS replacing my c library, not compatible with OS threads
by SankoR (Prior) on Nov 30, 2010 at 21:17 UTC | |
|
Re: XS replacing my c library, not compatible with OS threads
by Marshall (Canon) on Dec 01, 2010 at 08:59 UTC | |
by BrowserUk (Patriarch) on Dec 01, 2010 at 10:24 UTC | |
by Corion (Patriarch) on Dec 01, 2010 at 10:28 UTC | |
by BrowserUk (Patriarch) on Dec 01, 2010 at 11:08 UTC | |
|
Re: XS replacing my c library, not compatible with OS threads
by cdarke (Prior) on Dec 01, 2010 at 09:26 UTC |