在共享DLL中是否可能有多个单例实例? [英] Are Multiple singleton instances possible in a shared DLL?

查看:348
本文介绍了在共享DLL中是否可能有多个单例实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要为MFC应用程序开发一个DLL,并假设我有一个单例类在这个DLL中有一些同步机制。这个DLL被其他进程使用,即EXE。问题是:这个单例对于所有共享进程只创建一次,或者每个进程都有自己的单例?

I am going to develop a DLL for an MFC Application, and suppose I have a singleton class in this DLL with some synchronization mechanism. And this DLL is used by other processes, namely EXEs. The question is: is this singleton created only once for all sharing processes or every process has its own singleton?

如何解决这个多重单例问题? >

And How can I solve this multiple singleton problem?

推荐答案

我想你在谈论Windows。在这种情况下,每个进程都有自己的单例。您可以将其放在共享内存中,并使用命名的同步原语在进程之间共享单例。

I suppose you are talking about Windows. In that case every process has its own singleton. You could place it in shared memory and use named synchronization primitives to share singleton between processes.

这篇关于在共享DLL中是否可能有多个单例实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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