Use the thread library

TODO: Reformat

As MinGW uses the standard Microsoft C runtime library which comes with Windows, you should be careful and use the correct function to generate a new thread. In particular, the ~CreateThread function will not setup the stack correctly for the C runtime library. You should use _beginthreadex instead, which is (almost) completely compatible with ~CreateThread.

Failure to do this will lead to a small loss of memory if you use a large number of threads. However, it can also lead to the stack becoming misaligned, with disasterous consequences if MinGW starts emitting SSE instructions. In particular, the movaps instruction assumes that memory is aligned to a 16-byte boundary. MinGW (or, rather, the GCC compiler) handles this, but it assumes that the stack starts on a 16-byte boundary. Using _beginthreadex ensures this.

I believe that if you do not wish to use any C library functions, then ~CreateThread will work fine. However, _beginthreadex does the same job, and is safer.

_This might now be incorrect: it does not fix the problem I am having with SSE instructions, which seems to be a possible ~MinGW bug. Please edit, correct etc._

<b><BoHan></b> <i>~CreateThread does not always cause problems, it depends if the executable is linked against the static or the dynamic CRT, see</i>

Site Status

Site maintenance performed successfully, site online Dec 13th 12:00 AM Eastern.