I read producer/consumer queue implementation Producer/Consumer Queue. It works great, but i'm worrying if client forgets to call Shutdown(). How should i implement releasing of working threads? Thanks.
Asked
Active
Viewed 733 times
1 Answers
0
If Shutdown() is called when the program is to be shutdown, you can mark the threads as background threads when they are created. This means they will be stopped when the program is closed, but isn't always ideal as threads can be terminated forcibly.
Thread t = new Thread()
t.IsBackground = true;

Vok
- 457
- 5
- 19
-
No, it's not problem if app shutdown. Problem is application alive and reference to queue lost. Threads in this case stay alive. – FCBshnik Jun 25 '12 at 12:04
-
From a quick look at that code, it relies on adding null objects to the queue in order to end the threads. If you lose the reference to the queue then even if Shutdown() is called it will make no difference. Suggest adding to the worker threads something which checks for an abort request, that way you can call Thread.Abort() with or without the queue reference. Should be plenty of info out there with a quick search. – Vok Jun 25 '12 at 14:32