单例模式 - 早期绑定(涉及静态变量)是否减少了互斥锁的需要? [英] Singleton pattern - Does early binding (with static variables involved) diminish the need of mutex locks?
问题描述
所以,使用这种方法我们实际上不需要互斥锁?
我认为他们是指在开始/创建任何线程之前创建Singleton实例,从而减轻创建时的同步需求。
编辑:添加关于C ++和静态变量的信息
在C ++中,静态变量也在执行之前初始化,如David Harkness提到用于Java。 C ++中的一个问题可以在嵌入式环境中,直到系统初始化之后,才能执行对malloc / new的调用,在这种情况下,使用Singleton静态初始化程序可能会有问题。
They say that early binding solves the problem of synchronization. I couldn't understand "how". Is this something special to Java or the same applies to C++ too?
so, with this method we actually won't require a mutex lock?
I think they are referring to creating the Singleton instance before starting/creating any threads, thus alleviating the need for synchronization at creation.
EDIT: adding info about C++ and static variables
In C++, static variables are also initialized before execution like David Harkness mentions for Java. One issue with this in C++ can be in embedded environments where calls to malloc/new cant be performed until after the system is initialized, in which case using a Singleton static initializer could be problematic.
这篇关于单例模式 - 早期绑定(涉及静态变量)是否减少了互斥锁的需要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!