"ThreadLocal" is also available in LinuxC"

Source: Internet
Author: User
"ThreadLocal"-general Linux technology-Linux programming and kernel information is also available in LinuxC. The following is a detailed description. Now I am reading a book on Linux development and have come into contact with multi-thread development. I was surprised to find that I use C to Write multi-thread programs, and there are also threads.

The concept of internal variables, even called interfaces, is very similar to ThreadLocal in Java.

1. extern int pthread_key_create (pthread_key_t * _ key, void (* _ destr_function) (void *)));

Use this method to create a Key in the thread and bind a function to reclaim the space of the Key pair at the end of the thread.

2. extern int pthread_setspecific _ P (pthread_key_t _ key ,__ const void * _ pointer ));

Bind thread data with a key

3. extern void * pthread_getspecific _ P (pthread_key_t _ key ));

Obtain thread data

4. pthread_key_delete

Delete Key and corresponding thread data

It seems that the programming languages are the same.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.