Overview
| Artifact ID: | ba6121aeff5643e1d4a63059a15d9a9bcecf33fe |
|---|---|
| Ticket: | 406058ffffffffffffffffffffffffffffffffff |
| Date: | 2001-05-11 05:18:42 |
| User: | nobody |
| Artifact Attached: | cd653ea4f0ae03d30d1f727d526b9d3965f3671a |
| Filename: | test1.c |
| Description: | edited example from villalba |
Content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64/* Under deeper inspection of your code, I'd like to edit it for better cross-platform support of the threading macros in tcl.h. Honestly, casting of function types is evil. Especially the calling convention part. I don't think I'm being nit-picky because the compiler will emit different different machine code for __cdecl and __stdcall. Try it and look at the difference of the stack handling of the listing .asm file. */ #define TCL_THREADS 1 #include <tcl.h> #ifdef _MSC_VER # ifdef _DEBUG # pragma comment (lib, "tcl" STRINGIFY(JOIN(TCL_MAJOR_VERSION,TCL_MINOR_VERSION)) "dt.lib") # else # pragma comment (lib, "tcl" STRINGIFY(JOIN(TCL_MAJOR_VERSION,TCL_MINOR_VERSION)) "t.lib") # endif #endif Tcl_ThreadCreateType ThreadMainProc(ClientData clientData) { int *I = (int *) clientData; *I = 0; // if Tcl_ExitThread() is not called, Tcl_FinalizeThread() isn't // called either. That can lead to a large resource leak depending // on how much of the Tcl API is initialized. Tcl_ExitThread(0); // This just makes the compiler happy. TCL_THREAD_CREATE_RETURN; } int main(int argc, char *argv[]) { int I = 1; Tcl_ThreadId* ThreadId = NULL; Tcl_FindExecutable(argv[0]); // At this point the number of handles is 14 and of threads 1. if( Tcl_CreateThread( ThreadId, ThreadMainProc, &I, TCL_THREAD_STACK_DEFAULT, TCL_THREAD_NOFLAGS ) != TCL_OK) { return 1; // Error handle } // This loop is finished by the thread. // At this point the number of handles is 15 and of threads 2. while( I ) printf( "%d", I ); // At this point the number of handles is 15 and of threads 1, i.e. the thread is dead. return 0; }