mapping pthread id to custom id
-
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
-
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
-
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
-
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.
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
-
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