Solved

Converting a boost:thread::id  type to std long.

Posted on 2012-04-04
4
1,995 Views
Last Modified: 2012-04-11
I am creating a warpper for the boost::thread class. Many of our users do not like the boost's own types. So I have this function in my classs

long getId();

to give the users in std types.

The getId() simply get the id of the composed boost::thread object within my class. But the problem is boost::thread return their own type boost::thread::id when I call call the get_id() of the boost::thread . I want to oconvert this to long in my getId() functiion. So in essence...

how to convert

boost::thread::id to long?

-prain
0
Comment
Question by:prain
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 37808136
Don't do that, since it is not a thread ID. Depending on which platform your code is running, it is either a encapsulated 'pthread_t*' or a Windows HANDLE (see boost/thread/pthread/thread_data.hpp or boost/thread/win32/thread_data.hpp respectively).
0
 

Author Comment

by:prain
ID: 37812128
In out application we need some kind of an ID returned from the wrapper. therefore I tried doing a reinterpret_cast from boos::thread::id to long. It did not work.
0
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 37812194
That won't work since thread::id is a class and not a POD. There however is on operator for ostreams, so the following should work:

#include <sstream>

long thread_id_to_long(const boost::thread::id& tid) {

  long l;
  std::stringstream ss;

  ss << id;

  ss >> l;

  return l;
}

Open in new window

0
 

Author Closing Comment

by:prain
ID: 37833298
Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dialogbox API leak? 18 109
trigs fail! I thought I knew how to do trignometry 3 83
gdb doesn't stop on breakpoint 2 114
Adjust the codes 3 38
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This video teaches viewers about errors in exception handling.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question