Re: Threads on class,
From: Alexander Grigoriev (alegr_at_earthlink.net)
Date: 10/24/04
- Next message: Scott McPhillips [MVP]: "Re: What is the purpose of having static class functions?"
- Previous message: Tim Robinson: "Re: What is the purpose of having static class functions?"
- In reply to: Steve Maillet \(eMVP\): "Re: Threads on class,"
- Next in thread: Sigurd Stenersen: "Re: Threads on class,"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 23 Oct 2004 17:13:48 -0700
template<typename T, DWORD (T::*ThreadFunc)()>
DWORD ThreadFuncAdaptor(PVOID * arg)
{
return (static_cast<T*>(arg)->*ThreadFunc)();
}
CreateThread(NULL, 0, ThreadFuncAdaptor<MyClass, & MyClass::ThreadFunc>,
pMyClass,,,);
It's also possible to create an (templated) overload for CreateThread.
"Steve Maillet (eMVP)" <nospam1@EntelechyConsulting.com> wrote in message
news:OlMo6xUuEHA.3860@TK2MSFTNGP09.phx.gbl...
> I've never said it didn't or wouldn't work - I just said the technique had
> some flaws as a general solution to using C++ class member functions as
> threads. You've posted updated code to resolve the items I mentioned. (and
> they now appear in my news reader). The claim that it won't work on an x86
> was wrong. He clearly missed the use of __stdcall in there and how it
> resolves that particular issue.
>
> I don't think code samples are really all that necessary as Carl has
> defined rather explicitly where the problem lies and the types of code
> structure (or compiler switches) that force the compiler to use a pointer
> to member function representation that is incompatible with the pointer
> casting technique used in the solution thus far. Getting around that
> requires more significant effort.
>
> I have not posted code for getting around the pointer to member type issue
> as I cannot legally do so. My company has a framework for threading that
> resolves that issue and I can't just post that code, sorry. It is
> currently a small part of a larger solution for BSPs and thus not priced
> in a range useful for someone doing application development. (If all you
> wanted was the threading library it probably would be cheaper to do it
> yourself) I'm now working to see if we can get that pulled out as a more
> reasonably priced stand alone product. We'll see what comes of that.
>
> --
> Steve Maillet
> EmbeddedFusion
> www.EmbeddedFusion.com
> smaillet at EmbeddedFusion dot com
>
>
- Next message: Scott McPhillips [MVP]: "Re: What is the purpose of having static class functions?"
- Previous message: Tim Robinson: "Re: What is the purpose of having static class functions?"
- In reply to: Steve Maillet \(eMVP\): "Re: Threads on class,"
- Next in thread: Sigurd Stenersen: "Re: Threads on class,"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|