RE: Threading Issue

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I understand your problem. More generally, one might have multiple threads
and each thread might have multiple outputs. Raising an event on a
particular thread sounds like a nice idea, but I dont think it can be done.
My answer to this program organization issue is as follows:

1. A class that contains a Queue property.
2. Thread-safe Enqueue and Dequeue methods (worker threads enqueue, the
calling thread dequeues)
3. What gets enqueued and dequeued is always an array of objects (I
sacrifice strong typing for flexibility). In my game, the zero'th entry is
always a string that defines what follows. Enqueue has an arg like 'ByVal
ParamArray Data() As Object'.
Dequeue is a function returning Object().
4. The class also has Form and Timer properties. If set to other than
Nothing, whenever data is enqueued, the class does an Invoke to enable the
timer for an immediate tick, and this is how the worker thread dings the main
thread. If you prefer, your main thread could just poll the queue.
5. Not essential to the concept is the fact that I actually use three
queues, flash, normal, and idle. Worker threads can enqueue to any queue,
but dequeue always gives preference to flash over normal, and normal over
idle. It is a useful gimmick for my apps, but it is not essential.
6. Total size of the class is about 60 lines of VB, maybe 100 total with
comments and whitespace.

I know this sounds like overkill given your question, but my multi-thread
programs evolved in this direction, and I am content with it. To me it is
just a bit of threading infrastructure. I also don't claim it is the best
way - it is just my way.

Finally, be advised - if your main thread is a form thread, then the 'dirty
hack' of some variant of Invoke is absolutely necessary.

.



Relevant Pages

  • Re: How to evaluate an expression using Queue?
    ... but I need to use Queue structure. ... done; dequeue and return it. ... calculate the result and enqueue it in B, ... become a single value in A, with B empty; and that will satisfy the ...
    (comp.programming)
  • RE: [PATCH 1/2] NET: Multiple queue network device support
    ... Subject: NET: Multiple queue network device support ... repsonsible to acquire the lock for qdisc_restart. ... lock queue 1, and enqueue the packet. ... queue checked in dequeue for an skb, so I cannot rely on that lock ...
    (Linux-Kernel)
  • Re: A Queue implementation of doubly linked list in C
    ... for a broken queue and not others?" ... struct my_list* next; ... enqueue(m, "comp"); ... dequeue(m); ...
    (comp.lang.c)
  • Re: pop/push, shift/unshift
    ... on which end of the queue you were operating on. ... the array). ... have to figure out what people have aliased enqueue and dequeue to ...
    (comp.lang.ruby)
  • Am I doing this right?
    ... that packet data in a structure, and places the structure into a vb.net ... Queue (use enqueue. ... dim tmpStruct as NEW myDataStruct ... though the enqueue showed fine. ...
    (microsoft.public.dotnet.languages.vb)