Error returning void*

Hi guys,

I#ve got some kind of an issue here. I'm using pthread (POSIX), which is a c library and therefore not able to handle memberfunctions. I wrote a little work-around which static_cast's my memberfunction like so:

1
2
3
4
5
6
template<typename TYPE>
void* launchUpdateStats(void *obj)
{
	static_cast<lattice<TYPE> *>(obj)->updateStats();
	//return myObj->updateStats();
}


If I uncomment the return statement it gives me an error returning something in a void* function...
Now it works but gives me a warning to not return something in a *void function...

What is wrong here?
Blink hard and look at those two lines of code again.
You don't even want both lines.
so I just make the whole function void and remove the return line, right?
If you make it return void, you can no longer pass it to pthread_create.
But you're first calling updateStats on the casted obj pointer, then trying to call updateStats again on an apparently non-existant "myObj". And trying to return whatever updateStats returns. Does it even return a pointer?

Besides, you should use Boost.Thread or another C++ library. As you already stated, pthread is a C library.
Oh yes, I see - thanks. Boost sounds interesting, I'll look into that...
And another puzzler:
(I don't have the time to rewrite my proggy right now, I need to get my masters theses done! But I'll look into Boost next time...)

If I declare the function void, not return anything and call "&launchUpdateStats" within pthread, it should be fine?! (might be a coward's way, but should work yes?)

Best, ZED
pthread_create expects a function that returns void*, so it can't be void. Just return 0.
Thanks alot!
Topic archived. No new replies allowed.