Akleson
28-10-2005, 18:28
Hallo
Prizipiell weiss ich wie man mit Threads umgeht, aber ich würde gerne wissen, ob es nicht eleganter geht. Ich beschreibe einfach mein Problem mit zwei Beispiel Codestücken.
So läuft es
void * threadFunk(void * argp)
{
((A*) argp)->funk();
}
class A {
public:
pthread_t t;
void funk() {
...
}
void classFunk() {
pthread_create(&t, NULL, threadFunk, this);
}
};
Ich finde die global definierte Funktion aber nicht wirklich schön. Ich hätte lieber so was wie
class A {
public:
pthred_t t;
void * funk(void * argp) {
...
}
void classFunk() {
pthread_create(&t, NULL, funk, NULL);
}
};
Leider meckert bei mir der Compiler, dass im das dritte Argument nicht schmeckt. Kennt jemand einen Workaround oder eine andere Lösung?
Gruss
Prizipiell weiss ich wie man mit Threads umgeht, aber ich würde gerne wissen, ob es nicht eleganter geht. Ich beschreibe einfach mein Problem mit zwei Beispiel Codestücken.
So läuft es
void * threadFunk(void * argp)
{
((A*) argp)->funk();
}
class A {
public:
pthread_t t;
void funk() {
...
}
void classFunk() {
pthread_create(&t, NULL, threadFunk, this);
}
};
Ich finde die global definierte Funktion aber nicht wirklich schön. Ich hätte lieber so was wie
class A {
public:
pthred_t t;
void * funk(void * argp) {
...
}
void classFunk() {
pthread_create(&t, NULL, funk, NULL);
}
};
Leider meckert bei mir der Compiler, dass im das dritte Argument nicht schmeckt. Kennt jemand einen Workaround oder eine andere Lösung?
Gruss