Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ std::thread problems in Visual Studio 2012

I'm trying to execute this code.

BOOL genFunctionOne(std::vector <char> functionOneBuffer, int functionOneCharCount)
{
  int lineCountTest = 0;
  int characterCountTest = 0;

  for (int i = 0; i < functionOneCharCount; i++)
  {
    if (functionOneBuffer[i] == '\n')
      lineCountTest++;

    characterCountTest++;
  }

  return FALSE;     
}

With this call.

std::thread funcThreadOne( [&] { functionOne = genFunctionOne( functionBufferOne, functionCharCountOne ); } );

And everytime I call the function. I get..

Microsoft Visual C++ Runtime Library

Debug Error!

Program:... my.exe

R6010
-abort() has been called

Please retry to debug the application.

The Break Point is cause by... crt0msg.c

            if (rterrnum != _RT_CRNL && rterrnum != _RT_BANNER && rterrnum != _RT_CRT_NOTINIT)
        {
            switch (_CrtDbgReportW(_CRT_ERROR, NULL, 0, NULL, L"%s", error_text))
            {
            case 1: _CrtDbgBreak(); msgshown = 1; break;
            case 0: msgshown = 1; break;

Thanks in advance.

I have actually tried to run other thread calls in the same program and have had no luck. It could be my compiler, are there any libraries that need to be linked in build options with #include ?

like image 570
LightKeep Avatar asked Sep 26 '26 15:09

LightKeep


1 Answers

Do you join or detach the thread before exiting scope? Because you have to. Exiting scope with a thread running calls terminate.

like image 79
cooky451 Avatar answered Sep 28 '26 04:09

cooky451



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!