Hi All,
I'm moving some code over from ptheads to c11 threads in existing code. In my ptheads the pthread is declared in a global structure then called from a function when needed. I've tried to port this straight over to c++ threads and am getting a compile error ( error: no match for call to (std::thread) (void (&)())
). Basically I have a structure that holds my thread data
Code:
typedef struct thread_data
{
std::thread thread_function;
bool is_it_runnning;
#blah....
this is held in a class for my io function data
Code:
class IO_FunctionData
{
public:
/*constructor and deconstructor*/
IO_FunctionData();
~IO_FunctionData();
#blah
unsigned long get_inputs( void );
void start_io_thread( void );
bool get_io_thread_runnning_status( void );
private:
/*threads*/
struct thread_data io_thread;
I then start the thread with
Code:
void IO_FunctionData::start_io_thread( void )
{
io_thread.thread_function( in_thread );
}
this call the following function
Code:
void in_thread( void )
{
.....
so basically what I want to do is rather than start the thread as a "local" thread.
Code:
std::thread io_thread.thread_function( in_thread );
I want to be able to declare it "globally" then start it from any function I choose, so more like
Code:
io_thread.thread_function; //global
then call it from a function, eg
void foo( void )
{
io_thread.thread_function( in_thread );
}
If i start it locally it crashes the thread when the calling function ends. Can anyone advise. Sorry if some terminology is wrong.