I'm new to threads handling and I'm getting a bit confused as of why this bit of code doesn't work :
// Note that the GKITH object is useful for my whole code
void thread_function( gkit2light_Handler*& GKITH )
{
std::cout << "\t~ Writing from gkit2light thread..." << std::endl;
}
int main( int argc, char** argv )
{
// Custom gkit2light Handler
gkit2light_Handler *gkit_handler = new gkit2light_Handler( );
// Launching thread...
std::thread gkit_thread( thread_function, gkit_handler );
return 0;
}
I run it under macOS 10.13 using XCode 9. None of these lines actually throws me an error but my compiler gives me this message : « Attempt to use a deleted function ». This is weird because here the thread_function( ) only accesses the stdout...
Here it the deleted function, maybe this can help you !
struct __nat
{
#ifndef _LIBCPP_CXX03_LANG
// ...
// This is the destructor that is throwing the error
~__nat() = delete;
#endif
};
Here is a screenshot of the error (there isn't any more info): XCode compiler error screenshot
You cannot bind a reference like this while passing arguments to thread
(and this is stated in at least one reference). To pass a reference, use std::ref
to wrap it. This will survive the move/copy that happens to those arguments.
It's a shame that the toolchain kicks out such an arcane error message, but it means that somewhere within its template metaprogramming it's trying and failing to instantiate some templates relating to the code you wrote.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With