Re: List<T> thread safety question

Tech-Archive recommends: Fix windows errors by optimizing your registry



> Actually I fetch the first item from the List, to process it,
>
> Telegram aTlg = ReceiveQueue[0];
> ReceiveQueue.Remove(aTlg);
> --> now the "aTlg" is processed....

Well, even if you want to get the value, I would still *guess* (not proven)
that it would be quicker (nominally) to use RemoveAt - i.e.

Telegram aTlg = ReceiveQueue[0];
ReceiveQueue.RemoteAt(0);
// blah

I haven't profiled it, but that would be my guess.

> I am blocking my RecieveQueue untill all messages in it are processed.....

You could try:

while(true) {
lock(ReceiveQueue) {
if(ReceiveQueue.Count==0)
break;
Telegram aTlg = ReceiveQueue[0];
ReceiveQueue.RemoteAt(0);
}
// pulse here perhaps?
}
}

This will still loop until the queue is empty, but will lock/unlock on every
iteration, exiting when empty. It might also need a PulseAll or something at
the end of each iteration to invite the other threads to the party...

Marc


.



Relevant Pages

  • Re: Splitting file
    ... No row was found for FETCH, UPDATE or DELETE; ... query is an empty table. ... UPDATE TABLE1 SET ... ...
    (comp.unix.shell)
  • Re: testing for endofline
    ... I've just completed defining some expandable iteration and I ... If list is not empty, at some stage expands to: ... space-tokens will be considered elements. ...
    (comp.text.tex)
  • Re: Generic Package
    ... I already could stop talking here, since iteration over set data ... Mark it as already visited in the iterator state and return it. ... Empty -- construct an empty set ... Element -- Extract Element from Cursor ...
    (comp.lang.ada)
  • Re: getlist question
    ... Victor Subervi wrote: ... > getlist doesn't fetch anything because there is nothing to fetch! ... Does it return an empty list? ... "Nothing" is not a Python object, ...
    (comp.lang.python)
  • Re: getlist question
    ... Victor Subervi wrote: ... "Availability" field naturally enough; however, as I stated before, the ... getlist doesn't fetch anything because there is nothing to fetch! ... Does it return an empty list? ...
    (comp.lang.python)