   I Think My Server Is Trying To Kill My PC (C++ Win32 Threading)
  Hello I am running three threads excluding the main thread which barely does anything because I highly doubt it's causing any trouble for me. But anyways I created a server using Winsock and Win32's Threading support. Anyways here is whats going on.Alright so on thread one I have downloads and thread two does uploads and thread 3 does account information(File Deletion, Get Long Account Info, etc).Basically all three threads have a while loop and do not pause even if the clients aren't doing anything with them, but if I keep them running even though nothing is going on inside of the while loops with any of the clients the 3 threads seem to be speeding up my video card fan slowly and my CPU usage is 100% and I'm using a Triple core Athlon 440!I didn't think a thread using a nonstop while loop would harm anything, but do I have to pause my loops using the suspendThread function or is there a alternative?Can someone tell me what the heck is going on? I'm not even using graphics for my server, it's just like a command prompt application. Thank you, Andrew.   
Quote:I didn't think a thread using a nonstop while loop would harm anything, but do I have to pause my loops using the suspendThread function or is there a alternative?There are 2 choices:Have the threads "sleep" inside their loop.*Using the sleep call will have the thread give up some time (granularity is "at least" the given time not "at most" or "exactly". It usually rounds to 15ms steps in windows).Have the threads wait on a synchronization primitive or system call while waiting for work.*Having the upload and account info threads wait on a Condition Variable will put them to sleep till signaled. You can then signal the CV from the download thread when they get new instructions.*If you use synchronous network calls (ie. "blocking" calls), the thread will effectively sleep while the network command is waiting for data.Same thing with any synchronous system command, like file io.   ;  Hey thank you very much guys! Those methods work pretty well, it's really working! My video card doesn't sound like it's trying to go back in time. :)My CPU is keeping a good 10-50% usage rate with the server and client running with Chrome and other programs running, so I think I have a safe running server.   ;Just one week left to answer our short survey for a chance to win a semi-fabulous prize! View the full article