?
Solved

Can I have two Critical sections in a thread?

Posted on 2004-04-27
3
Medium Priority
?
228 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 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