473,473 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

mutual exclusion issue

13 New Member
hello ive got an application wich uses a collection in this case a queue from diffrent thereads

an object gets enqueued in one thread while anouther gets dequeued in a diffrent thread

these actions might accure simultaneously wich would resolve in an exception such as argument out of range exception , when the collections counter is being redifined.

now im looking for a "good looking" and right why to exclude these actions from one anouther

(1)what i mean by "good looking" is that i dont want to create my own collection derived from this one wich includes a lock(object) machenisem

(2) i dont want to use the brain storming idea i hade, wich is pretty "ugly"

enqueueOk = false;
while (enqueueOk)
{
try
{
Qsockets.Enqueue(currentSoc);
reEnqueueOk = true;
}
catch { }
}

i thought of course using the a lock or a mutex but that would be the case only if i wrap these actions in a procdure wich would be called from each thread,abd decide either to enqueue or dequeue wich would also be long and "ugly"

any ideas would be appricated ...
10x
Mar 28 '11 #1
2 1673
GaryTexmo
1,501 Recognized Expert Top Contributor
If you're accessing an object across multiple threads, I still think you should do locking. It's better to be safe with that kind of thing. That's not a very hard thing to do though, just surround your object with a lock block...

Expand|Select|Wrap|Line Numbers
  1. List<string> myList = new List();
  2. ...
  3. lock (myList)
  4. {
  5.   // do an action on myList here
  6. }
Anyway, more to your point... can you use the Exists method (present on a List and there's a similar for a hashtable... not sure of your data type) to see if something is in your queue before you try to access it?

Expand|Select|Wrap|Line Numbers
  1. lock (myList)
  2. {
  3.   if (myList.Contains(item))
  4.     myList.Remove(item);
  5. }
Something like that?
Mar 28 '11 #2
hype261
207 New Member
I would consider using a Semaphore for your problem instead of a Mutex. The Semaphore is designed for situations where you have a producer and consumer relationships.
Mar 29 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Morten Gulbrandsen | last post by:
Hello Programmers, Thank you for the kind advice, I have another small problem with MySQL I'd like to investigate, All I get is this:=20 ERROR 1005 at line 47:=20 Can't create table...
5
by: clusardi2k | last post by:
Hello, I have a assignment just thrown onto my desk. What is the easiest way to solve it? Below is a brief description of the task. There are multible programs which use the same library...
0
by: Support | last post by:
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <head>...
78
by: wkehowski | last post by:
The python code below generates a cartesian product subject to any logical combination of wildcard exclusions. For example, suppose I want to generate a cartesian product S^n, n>=3, of that...
1
by: othellomy | last post by:
I am trying to exclude all strings that has 'a' inside (I have simplified the actual problem) select 1 where 'bb b a dfg' like '%%' However, the above does not work. By the way, I can not use...
1
by: illegal.prime | last post by:
So I have a container of objects that I don't want to iterate across when I'm modifying it. I.E. I lock on adds and deletes to the container - so that my traversals of it don't result in...
9
by: Anthony Paul | last post by:
Hello everyone! I've been reading a great book on SOA called "Enterprise SOA" and found that it answered many questions. However, there's one particular scenario (involving business-rules)...
6
by: Scott | last post by:
I have two threads that share a python list. One thread adds to the list with append(), the other thread removes items with pop(). My question is -- are python list operations atomic? If they are...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.