| | |
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);
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.
•
•
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
Views: 345 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






