Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在C++;?_C++_Multithreading_Pthreads_Ssl - Fatal编程技术网

C++ 如何在C++;?

C++ 如何在C++;?,c++,multithreading,pthreads,ssl,C++,Multithreading,Pthreads,Ssl,我正在Nucleus RTOS上的移动平台上工作。它使用Nucleus线程系统,但不支持显式线程本地存储,即TlsAlloc、TlsSetValue、TlsGetValue、TlsFree API。平台也没有用户空间pthread P>发现大多数C++编译器中存在线程存储修改器。但我不知道如何使它适合我的使用。_u_线程关键字如何映射到显式线程本地存储?我读了很多文章,但没有什么能给我提供以下基本信息 每个线程的线程变量会不同吗 如何书写和阅读?每个线程都有变量的一个副本吗 以下是基于pthr

我正在Nucleus RTOS上的移动平台上工作。它使用Nucleus线程系统,但不支持显式线程本地存储,即TlsAlloc、TlsSetValue、TlsGetValue、TlsFree API。平台也没有用户空间pthread

<> P>发现大多数C++编译器中存在线程存储修改器。但我不知道如何使它适合我的使用。_u_线程关键字如何映射到显式线程本地存储?我读了很多文章,但没有什么能给我提供以下基本信息

  • 每个线程的线程变量会不同吗
  • 如何书写和阅读?每个线程都有变量的一个副本吗
  • 以下是基于pthread的实现:

    pthread_key_t m_key;
    
    struct Data : Noncopyable {
            Data(T* value, void* owner) : value(value), owner(owner) {}
    
    
            int* value;
    
      };
    
    
    inline ThreadSpecific()
    {
        int error = pthread_key_create(&m_key, destroy);
        if (error)
            CRASH();
    }
    
    inline ~ThreadSpecific()
    {
        pthread_key_delete(m_key); // Does not invoke destructor functions.
    }
    
    inline T* get()
    {
        Data* data = static_cast<Data*>(pthread_getspecific(m_key));
        return data ? data->value : 0;
    }
    
    inline void set(T* ptr)
    {
        ASSERT(!get());
        pthread_setspecific(m_key, new Data(ptr, this));
    }
    
    pthread\u key\u t m\u key;
    结构数据:不可复制{
    数据(T*value,void*owner):值(value),所有者(owner){}
    int*值;
    };
    内联线程特定()
    {
    int error=pthread\u key\u create(&m\u key,destroy);
    如果(错误)
    崩溃();
    }
    inline~ThreadSpecific()
    {
    pthread_key_delete(m_key);//不调用析构函数。
    }
    内联T*get()
    {
    Data*Data=static_cast(pthread_getspecific(m_键));
    返回数据-数据->值:0;
    }
    内联空集(T*ptr)
    {
    断言(!get());
    pthread_setspecific(m_键,新数据(ptr,this));
    }
    
    如何使上述代码使用_u线程方式来设置和获取特定值?创建和删除在何处/何时发生

    如果不可能,如何编写定制的pthread_setspecific、pthread_getspecific类API

    <>我尝试使用C++全局映射,并为每个线程唯一地索引它,并从中检索数据。但效果并不好

    当需要线程本地存储时,我一直使用库。我不知道它是否适用于您的系统。如果是这样的话,请查看课程

    对于
    \u线程
    关键字,有一个wikipedia,其中对其进行了描述