| | |
pthread issue with the function to be run
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 31
Reputation:
Solved Threads: 0
Hi all,
I am new to threads in c++, and I must use the pthread library. The documentation is easy to understand, but there is a more general aspect that I am missing. My question is: Is it possible to give a pointer to an object's function as argument to pthread_create()?
I tried, without success, something like this:
Thank you
I am new to threads in c++, and I must use the pthread library. The documentation is easy to understand, but there is a more general aspect that I am missing. My question is: Is it possible to give a pointer to an object's function as argument to pthread_create()?
I tried, without success, something like this:
cpp Syntax (Toggle Plain Text)
struct Obj{ int i; Obj( int n ): i(n){} void* myfun(void* ptr){} } Obj o(6); pthread_create( handler, NULL, &(o.myfun), NULL);
Thank you
You have to mention the name of function and address of handler with pthread_create arguments.
C++ Syntax (Toggle Plain Text)
pthread_create( &handler, NULL, o.myfun, NULL);
Failure is not fatal, but failure to change might be. - John Wooden
I regret.
I didn't notice : Is it possible to give a pointer to an object's function.
You cann't use instance member function's address with pthread_create function. It must be static.
You have to use & (an address operator) with handler variable and do not put & (address operator) with o.myfun (which is 3rd argument). - but the must be static.
I didn't notice : Is it possible to give a pointer to an object's function.
You cann't use instance member function's address with pthread_create function. It must be static.
You have to use & (an address operator) with handler variable and do not put & (address operator) with o.myfun (which is 3rd argument). - but the must be static.
Last edited by adatapost; Jun 17th, 2009 at 6:07 am.
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Sep 2008
Posts: 31
Reputation:
Solved Threads: 0
Hi all,
Thank you adatapost for your attention and reply.
Just a while ago I found http://www.parashift.com/c++-faq-lit...o-members.html in which point 33.2 explicitly explains my situation.
Rui
Thank you adatapost for your attention and reply.
Just a while ago I found http://www.parashift.com/c++-faq-lit...o-members.html in which point 33.2 explicitly explains my situation.
Rui
![]() |
Similar Threads
- SQL Injection Attack (Database Design)
- SOAP Request/Response Issue (RSS, Web Services and SOAP)
- C++ function errors (C++)
- Help!!!!open function cannot run in IE (ASP.NET)
- Function Back to Main (C++)
- Min function (MS SQL)
- Passing a Value between an Array and Another Function (C++)
- "system" function (PHP)
- Arguments of a function (JavaScript / DHTML / AJAX)
- function declaration in MatLab (Legacy and Other Languages)
Other Threads in the C++ Forum
- Previous Thread: Correct the plz
- Next Thread: best open source c++ compiler
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






