Here the self identifier declares a thread local variable time.
这里的self标识符声明一个线程局部变量time。
Note that the address of a thread local variable is valid only as long as the thread in which the address was taken still exists.
请注意:只有在其中获取地址的线程仍然存在的情况下,线程本地变量的地址才有效。
In standard c, the effect of this is to forbid the use of the address of a thread local variable as an initializer for an object or pointer.
在标准c中,这种作法的效果是禁止将线程本地变量的地址用作对象或指针的初始值设定项。
Each thread in the application will have its own local variable time, thus enabling each application thread to track its time.
应用程序中的每个线程都有自己的局部变量time,因此每个应用程序线程可以跟踪自己的时间。
While no one would ever directly use the idiom in Listing 1, this code is very similar to the case where the lock associated with a synchronized block can be proven to be a thread-local variable.
虽然没有人会直接使用清单1中的形式,但是与这个代码非常类似的情况是:可以证实与synchronized块关联的锁是一个线程本地变量。
To create a thread-local variable, you instantiate an object of class ThreadLocal.
要创建一个线程局部变量,请实例化类ThreadLocal的一个对象。
Instead, the thread class was modified to support ThreadLocal by adding an instance variable to thread that holds a HashMap mapping thread-local variables to their values for the current thread.
相反地,人们通过给Thread添加一个实例变量(该变量用于保存当前线程的从线程局部变量到它的值的映射的HashMap)来修改thread类以支持ThreadLocal。
A thread-local variable effectively provides a separate copy of its value for each thread that USES it.
线程局部变量高效地为每个使用它的线程提供单独的线程局部变量值的副本。
Local static pointer variable is not thread safe?
静态局部变量的指针不是线程安全的?
Local static pointer variable is not thread safe?
静态局部变量的指针不是线程安全的?
应用推荐