-1
#include <iostream>
#include <thread>

void hi()
{
    std::cout<<"hi"<<std::endl;
}

int main()
{    
    std::thread t1(hi);   
    t1.join();    
}

I turned on C++ to study threads, but as soon as I started it, the following error occurred. The error only occurs when building with 64-bit debug. And the error is thrown when the main method exits. What's the problem?

enter image description here

enter image description here

video link: https://www.youtube.com/watch?v=cM6OJ5NgBMQ

Translated into English, the exception that occurred is as follows.

Exception thrown (0x00007FF670271350, test.exe): 0xC0000005: 0x0000000000006800 Access violation while writing location.

JY K
  • 7
  • 3
  • Can you show the call stack? – HolyBlackCat Oct 07 '22 at 07:06
  • 4
    please show a [mre], this code obviously isn't the code you are debugging (your code prints `hi`, this code doesn't) – Alan Birtles Oct 07 '22 at 07:15
  • @HolyBlackCat Added call stack to body. – JY K Oct 07 '22 at 07:27
  • 1
    The images have nothing to do with the code you posted. Please [do not post images of code, errors, or other text](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question). Post a [mcve] as text directly in the question. – n. m. could be an AI Oct 07 '22 at 07:58
  • When I run the code you posted, I get the same error as the image. What more information do I need to provide? – JY K Oct 07 '22 at 08:11
  • I didn't post any code. You posted code, and it [runs with no error](https://godbolt.org/z/TE17nhfWP). If the code you have posted runs with an error *for you*, post the error you've got *while running this very code*, **as text directly in the question**. Not as a link to an external image. Thank you. – n. m. could be an AI Oct 07 '22 at 08:20
  • Added video link: https://www.youtube.com/watch?v=cM6OJ5NgBMQ – JY K Oct 07 '22 at 08:30
  • The problem is likely to be due to the framework you're using. It works on Compiler Explorer: https://godbolt.org/z/jbWdEYPn6 – Den-Jason Oct 07 '22 at 08:34
  • I don't think your video is useful. Please post any errors you are getting as (English) text in the body of the question. – n. m. could be an AI Oct 07 '22 at 08:42
  • The error message has been translated and added to the text. – JY K Oct 07 '22 at 08:49
  • What compiler are you using? What are the exact commands used to build the executable? – n. m. could be an AI Oct 07 '22 at 08:57
  • Are you referring to Visual Studio by compiler? I am using version 22, and I am running it with f5 without a special command when building. – JY K Oct 07 '22 at 09:13
  • Visual Studio is an IDE. The compiler is probably MSVC. You may want to look at the [build logs](https://learn.microsoft.com/en-us/visualstudio/ide/how-to-view-save-and-configure-build-log-files?view=vs-2022) and perhaps post the log of a problematic build here. – n. m. could be an AI Oct 07 '22 at 09:17
  • 'test.exe' (Win32): Loaded 'D:\server\test\x64\Debug\test.exe'. The symbol is loaded. 'test.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. 'test.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. 'test.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. – JY K Oct 07 '22 at 09:35
  • 'test.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140d.dll'. 'test.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140_1d.dll'. 'test.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. 'test.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. – JY K Oct 07 '22 at 09:36
  • 'test.exe' (Win32): Loaded 'C:\Windows\System32\f_im.dll'. 0x2568 Thread terminated (code: 0 (0x0)). 'test.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. 'test.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. – JY K Oct 07 '22 at 09:36
  • 'test.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. 0x6b80 Thread terminated (code: 0 (0x0)). Exception raised (0x00007FF69A1413C0, test.exe): 0xC0000005: 0x0000000000000001 Access violation while reading location. – JY K Oct 07 '22 at 09:36

1 Answers1

0

Please change your project name. DO NOT use "test".(I meant delete this project and create a new one with different project name.) Because test.exe is already existed in windows. Visual Studio may not run your command.

jmchen
  • 1
  • 2
  • I am getting the same error in a new project. – JY K Oct 08 '22 at 01:51
  • @JY Check this post to see if it can help you. [link](https://stackoverflow.com/questions/64993943/what-where-is-scrt-common-main-seh/64994218#64994218) – jmchen Oct 08 '22 at 05:47