Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can I have two Critical sections in a thread?

Posted on 2004-04-27
3
Medium Priority
?
233 Views
Last Modified: 2010-04-05
As Title
0
Comment
Question by:seualive
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10935204
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
ID: 10935486
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 60 total points
ID: 10936301
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

597 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