单例模式 - 早期绑定(涉及静态变量)是否减少了互斥锁的需要? [英] Singleton pattern - Does early binding (with static variables involved) diminish the need of mutex locks?

查看:162
本文介绍了单例模式 - 早期绑定(涉及静态变量)是否减少了互斥锁的需要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们说早期绑定解决了同步的问题。我不明白怎么样。这是Java的特别的东西还是同样适用于C ++?

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?

推荐答案

我认为他们指的是在开始/创建任何线程之前创建Singleton实例,从而减少创建时的同步需求。

I think they are referring to creating the Singleton instance before starting/creating any threads, thus alleviating the need for synchronization at creation.

EDIT :添加关于C ++和静态变量的信息

EDIT: adding info about C++ and static variables

在C ++中,静态变量也在执行前初始化,如David Harkness for Java。在C ++中的一个问题可能是在嵌入式环境中,其中调用malloc / new不能执行,直到系统初始化,在这种情况下使用Singleton静态初始化器可能有问题。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆