0
votes

Problem: the operating system does not perform round-robin between the two threads and the system just hangs.

Our system is implemented as a HTTP Native Code Module in c++ for IIS/W2008 R2 64-bit. Scenario:

  • Request 1 arrives to the web server; a new thread (t1) is started by IIS. The thread is executing.

  • Request 2 arrives before request 1 is finished. The IIS starts a new thread (t2). This thread goes into a loop waiting for a shared resource to be available. This behavior is program by us. Since thread two (t2) goes into a loop it starts consuming 100% of the CPU.

Problem: the operating system does not perform round-robin between the two threads and the system just hangs. If it would switch the execution to the first thread, the shared resource would be released and the second thread could run as well.

Even stranger: This behavior does only occur when the machine as 1 CPU. If we add another CPU to the machine it works perfectly, switching between the two threads as expected. Nothings hang.

A workaround (and better programming too) that makes it work when having only 1 CPU is to put a "sleep(100)" in the loop when checking for availability of the shared resource.

Why does not the operating system perform round-robin between the two threads when it only has 1 CPU? Is it related to VMWare?

1
Unless you show us code, this is really hard to tell. There's many reasons things can be awry. - Tony The Lion
sleep is NOT good programming when dealing with threads, it has certain uses, but the use you're putting it to is wrrong. - Tony The Lion

1 Answers

1
votes

This thread goes into a loop waiting for a shared resource to be available

This sounds like the wrong way to synchronize things, you will need to do signaling between threads, so that the OS gets a hint to perform the context switch.