Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-04-04
4
Medium Priority
?
2,315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 600 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

596 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