c# - What is the point of this sleeping thread -


i going through code right not mine. in code there thread following code:

while (true) {      thread.sleep(int.maxvalue); } 

it catches interruptedexception , goes right loop, loop can't interrupted.

does know why thread exist, purpose is?

edit: full code, little bit more context:

using ikvm.attributes; using java.lang; using system; using system.runtime.compilerservices; namespace applicationnamespace { internal sealed class dedicatedserversleepthread : thread {     internal dedicatedserver thedecitatedserver;      [methodimpl(methodimploptions.noinlining)]     internal dedicatedserversleepthread(dedicatedserver dedicatedserver)     {         this.thedecitatedserver = dedicatedserver;         base.setdaemon(true);         this.start();     }     [methodimpl(methodimploptions.noinlining)]     public override void run()     {         while (true)         {             try             {                 while (true)                 {                     system.threading.thread.sleep(int.maxvalue);                 }             }             catch (system.threading.threadinterruptedexception)             {             }         }     }     static dedicatedserversleepthread()     {     } } } 

note earlier code uses non-standard libraries, lowercase sleep valid. using ikvm libraries (which based on java standard libraries, , used cross-compile java programs .net)

this java server program cross-compiled .net bytecode , decompiled. wasn't sure if had ever seen thread dedicated sleeping reason, , if reason was. ta.speot.is giving answer.

let's ignore code posted, since won't compile, , focus on whether thread sleeps forever serves purpose.

there's 3 reasons can think of thread job sleep, none of them particularly legitimate.

to nothing

the thread might exist nothing meaningful, forever. if tasked job of creating thread should not meaningful, ever, might come code.

to keep clr/process alive

if it's foreground thread, thread keep process , clr alive, if main thread completes. from msdn:

a managed thread either background thread or foreground thread. background threads identical foreground threads 1 exception: background thread not keep managed execution environment running. once foreground threads have been stopped in managed process (where .exe file managed assembly), system stops background threads , shuts down.

to cool down

it's possible tying thread sleep, other threads can meaningful work not started (e.g. if they're being scheduled inside threadpool or other environment). from daily wtf:

due bunch of data-crunching speedups, cpu's no longer have chance throttle down. heat built in server, fan controller fried , cpu's cooked. alternative purchasing redundant cooling, made me slow application down previous performance levels strategically placed sleeps.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -