Using Visual C++ 32-bit, I have a function that looks like this:
void CastTestSpell(byte *packet, int length)
{
ServerSend(packet, length);
}
I want to send the function call ServerSend(packet, length); in a new thread to break away from the current thread it’s on so that it won’t block it.
How can I do it?
Assuming you manage the buffer objects somehow, you can just do
(although I generally advise against the use of
detach(): you probably want to get hold of thestd::threadobject andjoin()it at a strategic point).The above code is using current standard C++ (C++ 2011). If it doesn’t compile your C++ system is based on an outdated standard: Multi-threading support, including
std::threadwas added since the previous standard.