zoukankan      html  css  js  c++  java
  • thread local storage

    Thread local storage allows multi-threaded applications to have a separate instance of a given data item for each thread. Where a single-threaded application would use static or global data, this could lead to contention, dead lock or data corruption in a multi-threaded application. One example is the C errno variable, used for storing the erro code related to functions from the Standard C library. It is common practice (and required by POSIX) for compliers that support multi-threaded applications to provide a separate instance of errno for each thread, in order to avoid different thread competing to read or update the value.

    related APIs in pthread.h.

    int pthread_key_create(pthread_key_t *key, void (*destructor)(void *));
    Returns 0 on success, or a positive error number on error

    int pthread_key_delete(pthread_key_t key);

    If successful, the pthread_key_delete() function shall return zero; otherwise, an error number shall be returned to indicate the error.

    int pthread_setspecific(pthread_key_t key, const void *value);
    Returns 0 on success, or a positive error number on error

    void *pthread_getspecific(pthread_key_t key);
    Returns pointer, or NULL if no thread-specific data isassociated with key

     

    references:

    Linux programming interface

  • 相关阅读:
    js验证邮箱
    输出一个金字塔
    仿QQ聊天软件2.0版
    zoj 3662 第37届ACM/ICPC长春赛区H题(DP)
    zoj 3659 第37届ACM/ICPC 长春赛区现场赛E题 (并查集)
    zoj 3640 概率dp
    hdu 5203 && BC Round #37 1002
    poj 3071 概率dp
    poj 2151 概率dp
    zoj 3460 二分+二分图匹配
  • 原文地址:https://www.cnblogs.com/Torstan/p/2700631.html
Copyright © 2011-2022 走看看