Solved

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

Posted on 2012-04-04
4
2,094 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 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

695 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