Klasse erstellt Thread als Memberfunktion
-
Hey!
Wenn ich jetzt möchte, dass eine Klasse einen Thread erstellt, welcher eine Memberfunktion dieser Klasse aufruft, komm ich dann wieder nicht um ne globale od. statische Hilfsfunktion rum? Und sind das eigentlich Performanceeinbußen?
MfG
-
Das macht man so:
class Foo { void Bar() { _beginthread(&StaticThreadFunc, 0, this); } static void StaticThreadFunc(void *arg) { Bar *bar = (Bar*) arg; bar->ThreadFunc(); } void ThreadFunc() { } };
-
Also kommt man um ne statische ned herum? Auf die Performance wird das aber sogut wie keine Auswirkung haben, richtig?
MfG
-
Wirst Du bestimmt nicht merken
.
-
Jochen Kalmbach schrieb:
Das macht man so:
class Foo { void Bar() { _beginthread(&StaticThreadFunc, 0, this); } static void StaticThreadFunc(void *arg) { Bar *bar = (Bar*) arg; bar->ThreadFunc(); } void ThreadFunc() { } };Bin ich jetzt durcheinander oder müssten nicht die "Bar" durch "Foo" ersetzt werden

schirrmie
-
Nee, hast vollkommen recht... hab ich nur so aus dem Kopf getippt

Also nochmals zum mitschreiben:
class Foo { void Bar() { _beginthread(&StaticThreadFunc, 0, this); } static void StaticThreadFunc(void *arg) { Foo *foo = (Foo*) arg; foo->ThreadFunc(); } void ThreadFunc() { } };