Re: pthread handle to int



On Mar 15, 8:49 am, DanBar <daniel.g.barr...@xxxxxxxxx> wrote:
On Mar 14, 4:49 pm, red floyd <redfl...@xxxxxxxxx> wrote:

I've got some third party code that I'm trying to port to OSS (H RVU).

The code is trying to convert a pthread_t to an int (to create a
unique ID).

Now, since under both SPT and PUT models, pthread_t is a structure,
this cast is failing (for the obvious reasons).

Does anyone have any ideas as how to deal with this ?  Are any of the
three fields in pthread_handle_t unique and invariant  on a per-thread
basis, so that I can use that field to convert to int?

Thanks.

I know what you mean. I found this piece of code that may help, just
adapt it for your particular need. It is taken from ACE_wrappers code

/**
 * @file tid_to_int.h
 *
 * $Id: tid_to_int.h 79902 2007-10-31 09:46:36Z johnnyw $
 *
 * Convert an ACE_thread_t to an integer in a way that doesn't rely
 * heavily on platform-specific configuration.
 *
 * @author Ossama Othman
 */

namespace
{
  template<typename thread_id_type, typename ace_thread_id_type>
  struct ACE_thread_t_to_integer_i
  {
    thread_id_type operator() (ace_thread_id_type tid)
    {
      // We assume sizeof(thread_id_type) >=
sizeof(ace_thread_id_type).
      return (thread_id_type) (tid);
    }
  };

  template<typename thread_id_type, typename ace_thread_id_type>
  struct ACE_thread_t_to_integer_i<thread_id_type,
ace_thread_id_type*>
  {
    thread_id_type operator() (ace_thread_id_type* tid)
    {
      // ACE_thread_t is a pointer.  Cast to an intermediate integer
      // type large enough to hold a pointer.
#if defined (ACE_OPENVMS) && (!defined (__INITIAL_POINTER_SIZE) ||
(__INITIAL_POINTER_SIZE < 64))
      int const tmp = reinterpret_cast<int> (tid);
#else
      intptr_t const tmp = reinterpret_cast<intptr_t> (tid);
#endif

      // We assume sizeof(thread_id_type) >=
sizeof(ace_thread_id_type).
      return (thread_id_type) tmp;
    }
  };

  template<typename thread_id_type>
  thread_id_type
  ACE_thread_t_to_integer (ACE_thread_t tid)
  {
    return ACE_thread_t_to_integer_i<thread_id_type, ACE_thread_t>()
(tid);
  }

}


Thanks. Unfortunately, I'm dealing with raw pthread_t, which is
defined as a 3 element struct (pointer, short, short).
I appreciate the help, though.


.



Relevant Pages

  • Re: Is this impossible ? ReadFile
    ... There could be many reasons why this is failing for you. ... > int a; ... > but ReadFile is always fail with INVALID PARAMETER. ...
    (microsoft.public.vc.language)
  • Re: Maintance of c++ code
    ... piotr5@xxxxxxxxxxxxxxxxx (Piotr Sawuk) wrote: ... I too use comments to document the reasons why I made one choice ... int get ... Bar* b = new Bar; ...
    (comp.object)
  • Re: Freeview HD recorders....when?
    ... Genuine choice means being able to assess the options on the basis ... Perhaps knowing the reasons might help us to understand better than simply ... Armstrong Audio http://www.audiomisc.co.uk/Armstrong/armstrong.html ...
    (uk.tech.digital-tv)
  • Creepiness (was Re: SoCalResults OCWCSDC Mixed Level Strictly 8/27)
    ... I have heard similar comments from longtime dancers at ... do not make a point of it for a variety of reasons including politeness, ... social conditioning not to complain, and lack of desire to get into arguments. ... there is some basis for the "creepy old guy" stereotype ...
    (rec.arts.dance)
  • Re: Why no type hints for built-in types?
    ... Maybe an alternative to "int" and "float" hints ... enforce that using "int" as type hint. ... general, and there may also be good reasons for not having it, but given ... typing (to a varying degree, the newer ones being more strict than the older ...
    (alt.php)