1

Sometimes I get a mutex deadlock(since I'm doing multithreading using Mutexes) when I brute force my c++ console application(win32) to exit by pressing the cross at the application's window toolbar, but not when I'm closing the application via the Windows Task Manager. I have to mention that it's all fine when I close the application using my built in exit command in the program which is exiting all the threads I've started. Can I do anything to prevent a deadlock when I'm closing the program using the "brute force" method?

grimgrom
  • 730
  • 1
  • 9
  • 18
  • Come on. Be serious, please. I'm wondering if it's even possible to track when the used close the console window? Else, tell me what "better code" is for this situation? – grimgrom Nov 22 '12 at 23:55
  • "Better code" means having more locality and maintainability in the way you lock mutexes, e.g. by using tested standard library components rather than rolling your own. Factor code so that you can understand it locally, piece by piece, and that you can be confident that each piece is correct unconditionally... or in fewer words, "better code" :-) – Kerrek SB Nov 22 '12 at 23:58
  • 1
    http://stackoverflow.com/questions/9369120/c-how-do-i-check-if-my-window-is-about-to-close – Minthos Nov 22 '12 at 23:59
  • 1
    Kerrek SB: That's not relevant, my way of doing multithreading is probably a proper way. This question is focused on the win32 console handling which seems like the actual problem. Why did you even answer me if you did not even want to help me from the very beginning? Some people... Though, thank you Minthos! – grimgrom Nov 23 '12 at 00:08

0 Answers0