Win32 Thread Interleaving
- From: Andrew_zep <Andrew_zep@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 19 Jan 2007 13:05:02 -0800
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
.
- Follow-Ups:
- Re: Win32 Thread Interleaving
- From: PLS
- Re: Win32 Thread Interleaving
- From: Michael K. O'Neill
- Re: Win32 Thread Interleaving
- Prev by Date: Re: How to access usbstor.sys
- Next by Date: Re: Win32 Thread Interleaving
- Previous by thread: Re: How to access usbstor.sys
- Next by thread: Re: Win32 Thread Interleaving
- Index(es):
Relevant Pages
|