[406] in Pthreads mailing list archive
proven's pthread with C++?
daemon@ATHENA.MIT.EDU (Alex H.K. Wong)
Wed Sep 11 00:25:23 1996
Date: Tue, 10 Sep 1996 21:07:21 -0700 (PDT)
From: "Alex H.K. Wong" <wong@CS.UCLA.EDU>
To: pthreads@MIT.EDU
Hi,
Please help by directly mailing to me, thanks a lot in advance!
I am using proven's pthreads-1_60_beta5 on Linux 1.2.13 and have two
questions when compiling with pg++ which comes with the package.
Say I have:
class A
{
public:
A(int);
.
.
.
void start(void) {
pthread_create(&thread, NULL, (void *)&run, (void *)this);
}
private:
int data;
pthread_t thread;
.
.
.
void run(void *);
};
and the compiler gives warning:
A.C: In method `void A::start()':
A.C: warning: ANSI C++ forbids implicit conversion from `void *' in argument
passing
Any suggestion to fix that?
Second, the "(void *)this" in
pthread_create(&thread, NULL, (void *)&run, (void *)this); is
clearly unnecessary since they are both members of Class A, but when I try
to pass a 0 or NULL instead, it ends up with a segmentation fault. If
pass, say, "(void *) &data", sometimes it works, sometimes it doesn't and
"data" would be corrupted when try to use in run(), if something else is
passed instead.
Any idea of what I should really pass in start() here?
Thanks,
Alex
wong@cs.ucla.edu