www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - threads

reply rko <rko_member pathlink.com> writes:
Can someone point me in the right direction please?
I have a class with several methods. one of those methods should be called as a
with new thread and do something untill the class is destroyed.
here is a test class that i experiment with:

class serverinit
{
private:
Socket listener;
ushort port;
Thread listenerthread;  
int (*fp)(void *);
initdata data;

public:

Socket listenerdata()             { return listener; }	// read property
Socket listenerdata(Socket value) { return listener = value; } // write property
ushort portdata()                 { return port; }	// read property
ushort portdata(ushort value)     { return port = value; } // write property
Thread listenerthreaddata()       { return listenerthread; }	// read property
Thread listenerthreaddata(Thread value) { return listenerthread = value; } //
write property

static int serverinitializer(void *dataorg)
{
Socket reciever;
initdata *data = cast(initdata *)dataorg;

for(;;)
{
try {
reciever = data.listener.accept();
assert(reciever.isAlive);
Thread newthread = new Thread(data.fp, reciever);
newthread.start();
}
catch {
if(reciever)
reciever.close();  
}
}
return 0;
} 

this(int (*fp)(void *),ushort onport)
{
assert(fp != null);
this.fp = fp;
port = onport;

data.fp = fp;
listener = new TcpSocket;
assert(listener.isAlive);
data.listener = listener;
listener.blocking = false;
listener.bind(new InternetAddress(port));
listener.listen(10);
listenerthread = new Thread(&serverinitializer, &data); // XXXXX
assert(listenerthread != null);
}

~this()
{
listener.close();
listenerthread.pause();
delete listenerthread;
}
}

with a debugger, i can see that the line XXXXX is executed, but the function
will not listen. when i don't use the data-initdata construct, i can not
compile, since this is not allowed in a static method.


richard
Jul 05 2005
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
when is listenerthread.start() called? I didn't see anything glancing 
through the code.

"rko" <rko_member pathlink.com> wrote in message 
news:dade2h$2m9u$1 digitaldaemon.com...
 Can someone point me in the right direction please?
 I have a class with several methods. one of those methods should be called 
 as a
 with new thread and do something untill the class is destroyed.
 here is a test class that i experiment with:
Jul 05 2005
parent reply rko <rko_member pathlink.com> writes:
In article <daec9m$ddq$1 digitaldaemon.com>, Ben Hinkle says...
when is listenerthread.start() called? I didn't see anything glancing 
through the code.

"rko" <rko_member pathlink.com> wrote in message 
news:dade2h$2m9u$1 digitaldaemon.com...
 Can someone point me in the right direction please?
 I have a class with several methods. one of those methods should be called 
 as a
 with new thread and do something untill the class is destroyed.
 here is a test class that i experiment with:
thanx that you even answered. when i came home i saw that too. shame is dripping from me. richard
Jul 05 2005
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"rko" <rko_member pathlink.com> wrote in message 
news:daehai$hqb$1 digitaldaemon.com...
 shame is dripping
 from me.
That's one of the more .. original expressions I've heard ;)
Jul 05 2005
parent pragma <pragma_member pathlink.com> writes:
In article <daf6na$13c5$1 digitaldaemon.com>, Jarrett Billingsley says...
"rko" <rko_member pathlink.com> wrote in message 
news:daehai$hqb$1 digitaldaemon.com...
 shame is dripping
 from me.
That's one of the more .. original expressions I've heard ;)
I'll say. Perhaps he meant to say "I'm all wet." - EricAnderton at yahoo
Jul 06 2005