I am trying to implement a per go routine statistics. I want to come up with an array such as statistics[number_of_thread][statistics_type] and update the stat from each go routine. Eventually, I can either display all stats per go routine or can sum up the values of a single stat type from all go routines and display that. For this I need to identify each go routine. If this was pthread, then in C, I can achieve this by using pthread_key right at the beginning of the thread function:
pthread_key_t trace_key; >>>> This is global
uint32_t gbl_ctr; >>> This is global
pthread_setspecific(trace_key,(void *)__sync_fetch_and_add(&gbl_ctr, 1)) >>> Used in thread function.
Then, while updating the statistics, I can use pthread_getspecific() which would return the value specific to the thread which I can use to index the row of the above 'statistics' structure.
Is there something similar to pthread key in GO?
Thanks in advance.