Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. mapping pthread id to custom id

mapping pthread id to custom id

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++helptutoriallearning
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    meerokh
    wrote on last edited by
    #1

    After creating a pthread, i am setting the thread id to a custom id using a map.

    pthread_t threads[noOfThreads];
    struct thread_data td[noOfThreads];// a struct which only contains int thread_id
    thread= pthread_create(&threads[i], NULL, startFunc, (void *)&td[i]);
    setID(threads[i], td[i].thread_id);

    SetID function

    setID(pthread_t pid, int id ){
    thread_ids[pid]=id;// How can i access this value in getID function??

    definition of map

    std::map thread_ids;

    I want to get the mapped value based on the key value in the following function but dont know how to do exactly. getID function

    getID() {

    if (thread\_ids.find(pid) ==thread\_ids.end()) return -1;
    return thread\_ids\[pid\];//
    

    }

    I am very beginner so spare me if i am making a stupid mistake and please point that and help me correcting it

    c++, pthread

    L 2 Replies Last reply
    0
    • M meerokh

      After creating a pthread, i am setting the thread id to a custom id using a map.

      pthread_t threads[noOfThreads];
      struct thread_data td[noOfThreads];// a struct which only contains int thread_id
      thread= pthread_create(&threads[i], NULL, startFunc, (void *)&td[i]);
      setID(threads[i], td[i].thread_id);

      SetID function

      setID(pthread_t pid, int id ){
      thread_ids[pid]=id;// How can i access this value in getID function??

      definition of map

      std::map thread_ids;

      I want to get the mapped value based on the key value in the following function but dont know how to do exactly. getID function

      getID() {

      if (thread\_ids.find(pid) ==thread\_ids.end()) return -1;
      return thread\_ids\[pid\];//
      

      }

      I am very beginner so spare me if i am making a stupid mistake and please point that and help me correcting it

      c++, pthread

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Why are you using a struct for a simple value, i.e. int? And why do you need to map the real thread id to some other value? It is not really clear what you are trying to do.

      M 1 Reply Last reply
      0
      • M meerokh

        After creating a pthread, i am setting the thread id to a custom id using a map.

        pthread_t threads[noOfThreads];
        struct thread_data td[noOfThreads];// a struct which only contains int thread_id
        thread= pthread_create(&threads[i], NULL, startFunc, (void *)&td[i]);
        setID(threads[i], td[i].thread_id);

        SetID function

        setID(pthread_t pid, int id ){
        thread_ids[pid]=id;// How can i access this value in getID function??

        definition of map

        std::map thread_ids;

        I want to get the mapped value based on the key value in the following function but dont know how to do exactly. getID function

        getID() {

        if (thread\_ids.find(pid) ==thread\_ids.end()) return -1;
        return thread\_ids\[pid\];//
        

        }

        I am very beginner so spare me if i am making a stupid mistake and please point that and help me correcting it

        c++, pthread

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Why are you using a struct for a simple value, i.e. int? And why do you need to map the real thread I’d to some other vale? It is not really clear what you are trying to do.

        1 Reply Last reply
        0
        • L Lost User

          Why are you using a struct for a simple value, i.e. int? And why do you need to map the real thread id to some other value? It is not really clear what you are trying to do.

          M Offline
          M Offline
          meerokh
          wrote on last edited by
          #4

          I am planning to have more variable in the struct e.g.

          struct thread_data {
          int thread_id;
          const char *message;
          double result
          };

          Richard MacCutchan wrote:

          And why do you need to map the real thread id to some other value?

          The application in which i am creating pthreads is a simulation environment on top of which my actual thread scheduling library will execute so the each pthread act like virtual core. Each core(pthread) has its own work package queue from which it retrieves the package for execution and when it is empty it attempts to steal from other cores(via work stealing method). Every core has a package manager singleton class which is responsible for adding and getting the package from the queue. In order to access the other cores(using the singleton class) i need the mapping so that whenever each core access the package manager class (and its queue), it do based on the custom id. I hope i explained it better this time

          L 1 Reply Last reply
          0
          • M meerokh

            I am planning to have more variable in the struct e.g.

            struct thread_data {
            int thread_id;
            const char *message;
            double result
            };

            Richard MacCutchan wrote:

            And why do you need to map the real thread id to some other value?

            The application in which i am creating pthreads is a simulation environment on top of which my actual thread scheduling library will execute so the each pthread act like virtual core. Each core(pthread) has its own work package queue from which it retrieves the package for execution and when it is empty it attempts to steal from other cores(via work stealing method). Every core has a package manager singleton class which is responsible for adding and getting the package from the queue. In order to access the other cores(using the singleton class) i need the mapping so that whenever each core access the package manager class (and its queue), it do based on the custom id. I hope i explained it better this time

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Quote:

            whenever each core access the package manager class (and its queue), it do based on the custom id.

            Why not the real id?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups