PDA

View Full Version : Thread stops after a while in release mode



huba
21st July 2010, 00:15
Hi everyone!

I have experienced strange behaviour of my multi-threaded application I cannot explain.
It works fine when compiled in debug mode, but when it is compiled in release mode (on Windows XP) and then run it looks that the threads (I have about 20 of them) stop one by one in periods of several seconds.

I've found out in QT docs that some OS may have limitations on how many threads can the application have. But I haven't found anywhere how many it is on Win XP. Does any of you have experiance with that number of threads on Windows XP to share your experiance with me please? And why they stop not straight ahead, but after a while and only in release mode??? I have no clue:(

wysota
21st July 2010, 00:36
I would rather look for a life-lock in your code and not a limit for the number of threads that can be spawned at the same time. I assure you there is no problem in running several hundreds threads on a Windows system. Of course there is also another issue - do you have >20 processors in your system? If not then it is nothing unexpected that not all threads run at the same time.

huba
21st July 2010, 00:58
Thanks for your answer wysota. I'll check about live-lock. I don't even know that there is a thing like live-lock so I didn't implement it explicitally, but maybe there is some default setting for this? I'll try to find out.
I have one processor and of course I know that the threads are not really running simultanously (I even rised a question about how prcessor time is shared in replay to your post: http://www.qtcentre.org/threads/32281-NESTED-threads.-one-thread-inside-another), but inmy program problem is that at the beginning they all run, but then switch off one by one. But what I can't understand most is what for the hell it is only in release mode. I'll check against live-lock and let you know when I solve it.

wysota
21st July 2010, 01:12
don't even know that there is a thing like live-lock so I didn't implement it explicitally
It's not something you implement, it's something you might get when your code is incorrect :) It is similar to a dead-lock situation which occurs when one object (thread) can never gain access to a resource (CPU, printer, file, whatever) it needs because it is always blocked by some other object. A life-lock is a situation when theoretically it may happen that the object gets access to the resource but in practice it never (or very rarely) happens and the object can never complete its task in expected time.

borisbn
21st July 2010, 04:29
Thread can be stopped when an exception was thrown in it. Surround whole thread's run function with try/catch(...) and log out an error message in catch section.
Now about debug and release. In release mode your code computes faster and memory layout is more compact, then in debug one.