LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-06-2004, 11:45 PM   #1
tushar123
LQ Newbie
 
Registered: Dec 2003
Location: mumbai
Distribution: shivatusahr
Posts: 14

Rep: Reputation: 0
pthread_create


The 3 rd argument to pthead_create is a function pointer.
and the format is void *(*start_routine) ( void *).

I want to use the class method as a start_routine.

I have defined a class called Handler which consist of a method
void* Handler :: ThreadHandler (void *);


I have tried to use as follows:
my code ...
.
.
.
pthread_t ThId;
int Id;
Handler objHandler;
.
.
.
pthread_create ( &ThId , NULL , &(objHandler.*ThreadHandler), &Id );

but it gives error of type miss match for 3rd argument.

Can I use this method as start_routine for thread .
Please let me know if there is another way to achive this.
 
Old 06-06-2004, 11:51 PM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
i tink c++ syntax is objHandler::ThreadHandler . but dont hold me to that.
 
Old 06-07-2004, 08:15 AM   #3
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Non-static class method functions use their own calling convention that stores a "this" pointer. In order to use a member function of a class as a C-style callback function, you generally need to make it static. However, you should be aware that because a static function doesn't use this same calling convention that stores a "this" pointer, the only class members you can access from a static function is other static members.
 
  


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
pthread_create... os2 Programming 4 05-26-2005 03:09 PM
error on pthread_create? adamjmac Programming 2 05-23-2005 06:21 PM
pthread_create problem live_dont_exist Programming 5 04-24-2005 06:21 AM
Pthread_create rahul_kulkarni Programming 4 02-10-2005 11:48 AM
pthread_create parameters AquamaN Programming 3 03-16-2004 10:05 AM

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

All times are GMT -5. The time now is 11:39 AM.

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