--- In Boost-Users@yahoogroups.com, "William E. Kempf"
olivier_debels said:
--- In Boost-Users@yahoogroups.com, "William E. Kempf"
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.