How can I destroy my instance?
Posted: Sun May 22, 2011 5:26 pm
I obviously don't know what I'm doing, and I'm doing something horribly wrong here, because what I want to do won't work.
I'm trying to set up a server class, using a Listen function as the constructor, and this function calls a Wait function that loops (until boolean done is set to 1) in a new thread.
When I want to shut down the server, obviously I need to do both of these:
[*] set done←1, which will stop the endless loop, and the thread will shut itself down naturally (I'd rather not ⎕TKILL the thread if I can help it)
[*] erase the class instance
I tried coding to set done←1 in the destructor, but on saying )erase xyz nothing happens because the destructor doesn't get called even though xyz is erased, because the instance carries on operating. My other thought is to get the instance to erase itself after the thread has shut down, but I can't figure out how to do that.
Ideally, I'd like to use )erase or ⎕EX to shut the server down and erase the instance. Has anyone got any thoughts on this?
I'm trying to set up a server class, using a Listen function as the constructor, and this function calls a Wait function that loops (until boolean done is set to 1) in a new thread.
When I want to shut down the server, obviously I need to do both of these:
[*] set done←1, which will stop the endless loop, and the thread will shut itself down naturally (I'd rather not ⎕TKILL the thread if I can help it)
[*] erase the class instance
I tried coding to set done←1 in the destructor, but on saying )erase xyz nothing happens because the destructor doesn't get called even though xyz is erased, because the instance carries on operating. My other thought is to get the instance to erase itself after the thread has shut down, but I can't figure out how to do that.
Ideally, I'd like to use )erase or ⎕EX to shut the server down and erase the instance. Has anyone got any thoughts on this?