How do I create a global variable that is thread-specific in C using POSIX threads?

后端 未结 3 769
[愿得一人]
[愿得一人] 2021-01-31 21:32

I am learning about POSIX threads and I have come to the section on Thread Specific Data. The book does an excellent example using a file descriptor. However, I wanted to do the

3条回答
  •  [愿得一人]
    2021-01-31 22:01

    In general, what you're looking for is "thread local storage". Here are a few links:

    • http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frzahw%2Frzahwex1.htm

    • http://en.wikipedia.org/wiki/Thread-local_storage

    Choosing pthread_getspecific() is correct. Here's a good example:

    • http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Fapis%2Fusers_34.htm

    Please review the above example: I think it will point you to the problem ... or suggest a good alternative.

    IMHO...

提交回复
热议问题