Boost logo

Boost Users :

From: olivier_debels olivier_debels_at_[hidden])
Date: 2002-12-17 04:36:14


--- In Boost-Users_at_[hidden], "William E. Kempf"
<wekempf_at_c...> wrote:
>
> olivier_debels said:
> > --- In Boost-Users_at_[hidden], "William E. Kempf"
<wekempf_at_c...>
> > wrote:
> >>
> >> olivier_debels said:
> >> >
> >> > I'm using boost_1_29_0 and need to get the id of the current
> > thread.
> >>
> >> Why?
> >>
> > I have several threads which pop messages from the queue. I
want to
> > keep track of what each thread pops (depending on some rules)
without
> > adding an extra parameter (threadId) in the pop-function.
>
> I don't follow this.

>
> > By this way threads just call the pop-function (they don't know
> > anything about the internal cooking of the queue). They get a
> > message, which fulfills the rules (one of the rules is f.e.
that no
> > two threads can handle the same message at the same time).
>
> How does a thread id figure into this? What little of this
description I
> understand gives no need for a thread id.
>
> William E. Kempf

Ok, sorry, I'll try to make it more clear.
You have a simple Queue where you can push and pop messages.
Popping is done by one or more threads.
The threads handle the message before popping the next one.
So far so good. This is very straightforward: threads pop a message,
handle it, pop a next message and so on...

Now, An adjustment must be done: Messages have a certain type and no
two threads are allowed to handle a message of the same type at the
same time.
The push and pop interface must stay the same (no extra parameters
are allowed...).
This means the pop function must now get the next message and check
if no other thread is handling such a message at the moment.

In order to do this, I wanted to store the type of message each
thread was working on. This means I have a map containing for each
thread, the message type he is working on (mapping a threadId onto a
message type, here is where the threadId comes in)

The pop function would then look something like this (in higher
level language):

  msg* pop()
  {
    // Get next message out of the queue
    // While no message found
    // Check if no other thread is working on such a messagetype
    // If not -> return this message
    // else -> get next message
  }

To check if no other thread is working on such a messagetype, we
take a look in the map(threadId, message type).

Hope this makes it more clear!

Olivier.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net