On 1 Dec 2007, at 19:40, Greg Ercolano wrote: > imm wrote: >> Thirdly: Don't use CreateThread, it has "issues" with how it >> interacts with the C runtime. > > Oh great.. I never noticed that. > > Will now have to look back through my apps to see if that's > causing any trouble.
To be honest, I don't recall ever actually tripping up on this one, and I always used to used CreateThread, but I've always made a point of using _beginthread since I read the docs... Looking at the docs, they now seem to recommend _beginthreadex - which makes sense I suppose, since it has essentially the same paramter list as CreateThread has, anyway. It's almost (give or take a little casting) a drop-in replacement for CreateThread. >> Even the M$ docs suggest that you use >> _beginthread instead. > > Cripes, they're actually recommending an underbar function > instead of their core API calls? > > Microsoft should just come right out and say not to use WIN32 > at all. Ha! The actual wording in MSDN online (I just checked, and this is different to what I remember it saying, so I guess it's been updated over the years...) is: "A thread in an executable that calls the C run-time library (CRT) should use the _beginthreadex and _endthreadex functions for thread management rather than CreateThread and ExitThread; this requires the use of the multi-threaded version of the CRT." IIRC, the original wording warned about the CRT not being initialised correctly by CreateThread and said to use either _beginthread or _beginthreadex instead. Hmm, I also see: "A quick browse of ...\VC\crt\src\tidtable.c shows that CRT (the C runtime library) keeps a per-thread data structure, pointed to from a TLS slot. The per-thread data structure keeps thread-local copies of errno, pointers to some char buffers (eg for strerror(), asctime() etc), floating-point state and a smattering of other stuff. This is dynamically allocated and initialised by _beginthread(), but obviously CreateThread can't do this since it knows nothing of the CRT." So I guess that might be a clue which things are likely to break in threaded code. -- Ian _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

