0

I'm working with a C++ DLL project. I tried to use simple boost thread in there. here is the source-code. this run time exception at uploadThread = boost::thread(uploadFileThread); line. Any idea?

Unhandled exception at 0x6fa1bd89 (Controller.dll) in UserInterfaces.exe: 0xC0000005: Access violation reading location 0xbaadf05d.

Controller.h

namespace controller{
class  CController {
public: 
boost::thread uploadThread;
}
}

Controller.cpp

namespace controller{
static void uploadFileThread(){}
void CController::StartFileUpload(){        
        uploadThread = boost::thread(uploadFileThread);
        uploadThread.join();
}
}

main.cpp

int main(){
controller::CController my_Controller;
my_Controller.StartFileUpload();
return 0;
}
Nayana Adassuriya
  • 23,596
  • 30
  • 104
  • 147
  • It's hard to say what, exactly, is wrong from the code you have posted, but you are using uninitialized memory. The Win32 heap will fill newly allocated memory with `0xBAADF00D` when a debugger is attached. – James McNellis Jan 31 '13 at 07:06
  • @JamesMcNellis- Thank you, I cannot exultantly understand what do you mean by second sentence. could you be kind to explain more. – Nayana Adassuriya Jan 31 '13 at 07:11
  • On Windows, if a debugger is attached to a process, newly allocated memory is filled with the byte pattern `0xBAADF00D` to help you to identify use of uninitialized memory. (The Win32 `HeapAlloc` function performs this fill). The exception message you quote reports that an access violation occurred when attempting to access the memory at address `0xbaadf05d`. The upper three bytes of this address are almost certainly uninitialized memory. – James McNellis Jan 31 '13 at 07:25
  • That code won't compile - you declare a class `CController` but define a variable of type `Controller`, there are missing semicolons, missing using directives or namespace specifiers etc. Main is supposed to return int, not void. Your class definition is missing the declaration of `StartFileUpload` and so on. Please give us a [SSCCE](http://sscce.org) from the *real* code, so we can see what the real problem is. – Arne Mertz Jan 31 '13 at 07:26
  • @ArneMertz - thank you. Corrected the main method. StartFileUpload is purposely declared as non member function. – Nayana Adassuriya Jan 31 '13 at 07:36
  • Still won't compile. To help us solve your problem, please be proactive and give us something useful - see the SSCCE link in my last comment. `error: expected ‘;’ after class definition` -- `error: no ‘void controller::CController::StartFileUpload()’ member function declared in class ‘controller::CController’` -- `In function ‘int main()’: error: ‘class controller::CController’ has no member named ‘StartFileUpload’` – Arne Mertz Jan 31 '13 at 07:46

0 Answers0