Solved

Can I have two Critical sections in a thread?

Posted on 2004-04-27
3
203 Views
Last Modified: 2010-04-05
As Title
0
Comment
Question by:seualive
3 Comments
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
seualive, the important property that critical sections have is that only one thread may have ownership at any one time. If a thread tries to enter a critical section when another thread is already inside the critical section, then it will be suspended, and only re awaken when the other thread has left the critical section.

Shane
0
 

Author Comment

by:seualive
Comment Utility
Thank you, Shane.
In my application I have two message queues (one for Recieve message and the other for Send message). Should I create two critical sections for each queue two avoid the threads operating the queues at the same time?
0
 
LVL 7

Accepted Solution

by:
sftweng earned 20 total points
Comment Utility
The only thing you should be concerned about is a "deadlock". Suppose you havetwo threads T1 and T2 and two critical sections controlled by mutexes M1 and M2. You need to avoid a situation where, e.g.:
1. T1 acquires M1
2. T2 acquires M2
3. T1 attempts to acquire M2 without releasing M1
4. T2 attempts to acquire M1 without releasing M2.

In your case, it might be best to have multiple separate threads for sending and receiving where only the sending threads acquire the sending mutex and only the receiving threads acquire the receiving mutex.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now