| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Multithreading member-functions |
Hi Peter.
PS> Is there any way to multithread a C++ Class member-function? I'm using
PS> VisualAge C++ 3.0, and I am trying to execute a member-function in a
PS> separate thread. But the compiler says "error EDC3167: The
PS> "_Optlink" qualifier cannot be applied to
"void()".". If I however
PS> move the function out of the class that works, but instead I can't
PS> pass *this on to it.
You can't start thread in class method -- class method has *this* as
first parameter. But you can start thread, and then call method, using
known pointer.
void APIENTRY ThreadBody( ulong p )
{
SomeClass* t = (SomeClass*)p;
p->SomeMethod();
};
SomeClass x;
DosStartThread(&tid,ThreadBody,(ulong)&x,0,32768);
*or*
(typed on-the-fly!)
class Thread
{
public:
static APIENTRY Wrapper(ulong p)
{
Thread* t = (Thread*)p;
t->Body();
DosExit(0,0);
};
void Run()
{
DosCreateThread(&tid,&Wrapper,(ulong)this,0,32768);
}
protected:
virtual void Body() = 0;
ulong tid;
};
and then:
class Typer : public Thread
{
void Body()
{
while(1) puts("still alive");
};
};
Typer a; a.Run();
// add error checking by taste.
bye. [Team OS/2]
dozen
SPb,Russia
--- FleetStreet 1.19 NR
* Origin: живи и дай умереть (2:5030/297.31)SEEN-BY: 50/99 54/99 270/101 620/243 625/155 711/401 413 430 934 712/311 407 SEEN-BY: 712/505 506 517 623 624 704 713/317 800/1 @PATH: 5030/297 110 48 16 464/34 5100/8 396/1 270/101 712/624 711/934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.