Solved

Can I have two Critical sections in a thread?

Posted on 2004-04-27
3
211 Views
Last Modified: 2010-04-05
As Title
0
Comment
Question by:seualive
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 20 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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