LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-27-2015, 10:31 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
c++ threads declared before the function call


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.

Last edited by knobby67; 03-27-2015 at 10:33 AM.
 
Old 03-27-2015, 11:39 AM   #2
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Original Poster
Rep: Reputation: 43
OK got it


std::thread global

function( void )
{
global = std::thread( function )l

}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error: call to ‘__open_too_many_args’ declared with attribute error: open can be call mohammad taqy bayat Other *NIX 0 09-06-2014 04:44 AM
error: call to ‘__open_too_many_args’ declared with attribute error: open can be call mohammad taqy bayat Linux - Software 1 09-02-2014 08:18 AM
Why must a function with weak attribute be declared before it's first use? (In gcc) cyent Programming 4 09-11-2013 04:08 PM
no member function declared in class...weird behavior... jaepi Programming 1 12-11-2007 10:23 PM
Howto access a variable outside the function from where it is declared in C daYz Programming 4 03-09-2007 01:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration