Win32 Thread Interleaving




Hi,

I read some post for win32 thread application and thought if you guys can
hep us.

we are developing trading platform for different exchanges and facing a
strange problem. Our application creates two threads both threads are running
for indefinate times (means there is no sleep in thread loop function).
Thread 1 will always check the queue for possible work to be done and Thread
2 always listens the network broadcast.

The code is something similar to

void *ThreadAFunct(void *arg){
While(true){

int workAvailable = CheckQueue();
//....
if(workAvailable){
LockMutex(sharedMutex);
//do some work
UnLockMutex(sharedMutex);
}
//.....
}
}

void *ThreadBFunct(void *arg){
while(true){
//.....
LockMutex(sharedMutex);
//ListenForBroadcast...
UnLockMutex(sharedMutex);
//........................
}
}

Both threads uses same mutex. and for acquiring and releasing mutex we are
using EnterCriticalSection and LeaveCriticalSection functions.

Now problem we are facing is, in windows XP hyper threaded processor,
threads get the mutexes in just a few milliseconds and never had any problem
with thread interleaving, threads releases after few milliseconds and other
thread acquires mutex in very little time. But we are seeing different
behaviour in windows 2003 server (SP1) hyper threaded machine. Thread doesn't
interleave perfectly like XP, sometimes a thread runs for long time compare
to other thread (I used timers and found out that Thread B gets most of the
processor time compare to thread A.)

And often (most consistantly and probably root of all these problems) thread
A waits for very long time just for acquring mutex (sometimes more than a min
some time just a second).


I am not getting why it works perfectly fine in windows XP. The same
application is running for over 3 months (on XP) but on windows 2003 it has
these problems. One possible solution would be to put Sleep() in Thread B
after reading certain number of broadcast. And it works but still can't get
bottom of the problem.

I wrote same program using WaitForSingleObject() and it works fine with
that, so wondering it might be something to do with the CriticalSection
functions.

I even tried setting different values for Win32PrioritySepration but didn't
worked.

So any suggestion would be helpful.

Thanks in advance

.



Relevant Pages

  • Re: WaitForSingleObject() will not deadlock
    ... And in what way am I wrong about Windows mutexes? ... expectations would violate the *documented* mutex behavior). ... building only experimental systems (my first synchronization system was ...
    (microsoft.public.vc.mfc)
  • Re: Why does Microsoft never document threading right?
    ... which is a fast mutex (and has ... CRITICAL_SECTION structure is implemented internally on Windows. ... object does not allow only one thread at time to execute the same code. ... It protects data, not code. ...
    (comp.programming.threads)
  • Re: Broadband connection terminates after around 5-10 minutes
    ... facing when I am using Broadband connection. ... I have Windows XP Professional OS on my machine. ... I have tried installing the Windows XP again, but I am facing the same ... it by tossing out the modem and installing a modem/router instead. ...
    (microsoft.public.windowsxp.general)
  • Re: Win32 Thread Interleaving
    ... Both threads uses same mutex. ... Now problem we are facing is, in windows XP hyper threaded processor, ... threads get the mutexes in just a few milliseconds and never had any problem ... with thread interleaving, threads releases after few milliseconds and other ...
    (microsoft.public.win32.programmer.kernel)
  • Broadband connection terminates after around 5-10 minutes
    ... facing when I am using Broadband connection. ... I have Windows XP Professional OS on my machine. ... screen and reboot the machine.Now, if I reboot the machine, I am able ... I have tried installing the Windows XP again, but I am facing the same ...
    (microsoft.public.windowsxp.general)