Solved

Can I have two Critical sections in a thread?

Posted on 2004-04-27
3
222 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 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