FIFO thread synchronizing
Hello,
i'm programming a multithreaded communication application. Some of the communication operations are being hold in a a shared (for all threads) synchronized queue. the synchronized queue is using c++ 'CRITICAL_SECTION' handle (using the 'EnterCriticalSection' and 'LeaveCriticalSection' functions).
have three questions (actually it's two):
1) Is 'CRITICAL_SECTION' ensure FIFO threads access into the critial sections of code?
2) If not, what can i use to ensure FIFO access?
3) If yes, is there a better (less CPU time, less resources) way to ensure FIFO access to critical sections of code?
thanks
[690 byte] By [
menny_ed] at [2007-11-19 4:19:30]

# 1 Re: FIFO thread synchronizing
[ Moved thread ]
# 2 Re: FIFO thread synchronizing
1) Is 'CRITICAL_SECTION' ensure FIFO threads access into the critial sections of code?
2) If not, what can i use to ensure FIFO access?
3) If yes, is there a better (less CPU time, less resources) way to ensure FIFO access to critical sections of code?
To answer all three questions in once...as long as you are working within the same process, you are fine with critical sections...
# 3 Re: FIFO thread synchronizing
To answer all three questions in once...as long as you are working within the same process, you are fine with critical sections...
As i understasnd, if my shared objects are shared in the same application only,
using CRITICAL_SECTION method will ensure FIFO access by the threads to the shared objects?
# 4 Re: FIFO thread synchronizing
As i understasnd, if my shared objects are shared in the same application only,
using CRITICAL_SECTION method will ensure FIFO access by the threads to the shared objects?
Oopppss...sorry...misunderstood your first question...no, if you need FIFO access, then you have to implement this on your own (using a critical section for example). Critical sections as well as other synchronization objects don't do it theirselves...
Sorry for the misleading answer in my previous post...
# 5 Re: FIFO thread synchronizing
...no, if you need FIFO access, then you have to implement this on your own (using a critical section for example...
Thanks.
i was quite suprised when you said that CRITICAL_SECTION IS implementing FIFO access. Could you point me to an implementation of a FIFO locking mechanism?
Or maybe give me some pointers to implement it myself?
thanks
# 6 Re: FIFO thread synchronizing
Well...actually no...since I never had such a problem yet...sorry...try searching the internet...
# 7 Re: FIFO thread synchronizing
hi.
please check this link:
http://www.codeproject.com/script/comments/forums.asp?forumid=1647&fr=76#xx1013134xx
Blake Miller claims that the CRITICAL_SECTION operations ARE in FIFO order.
could you point me to someplace that says it's not?
It's realy important that i'll figure it out.
thanks
# 8 Re: FIFO thread synchronizing
From MSDN:
The threads of a single process can use a critical section object for mutual-exclusion synchronization. There is no guarantee about the order in which threads will obtain ownership of the critical section, however, the system will be fair to all threads.
See:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/initializecriticalsection.asp
Hope this helps
# 9 Re: FIFO thread synchronizing
FYI:
See thread library in boost (www.boost.org). Although I haven't used that library except for small test applications the following link suggest that you can specify a FIFO Scheduling Policy for the mutexes in boost.
http://www.boost.org/doc/html/threads/concepts.html#threads.concepts.FIFO-scheduling-policy
Hope this helps
# 10 Re: FIFO thread synchronizing
Here's a class I wrote which does a FIFO queued critical section.
I've found that critical sections are NOT fifo queued which is why I wrote this. I've also found that under high loads with a large number of threads critical sections can cause thread starvation : i.e. some threads are permenantly waiting.
These classes are MFC based but should give you some idea about how to do this.
Darwen.
darwen at 2007-11-9 14:06:19 >

# 11 Re: FIFO thread synchronizing
Thanks alot guys.
i've tried to build a FIFO critical section which is implemented with EVENT handles, CRITICAL_SECTION, and a STL's list.
I've attached the files.
I think that it consumes too much CPU time. could you go over it?
thanks