Singleton per DLL instance

H

Herby

I am going to develop a multi-threaded application that creates many
instances of a calculator object. Consequently the DLL housing the
Calculator is to be thread safe.

Within the DLL i want some global singleton objects - these then become
accessible from all sub-objects comprising the calculator DLL. But i
only want these singletons to be accessible from anywhere within the
current calculator instance not across all calculators.

Its usual to make singletons static. But this would then make it
accessible across all concurrent instances, thus compromising my thread
safety.

How can i have a DLL instance singleton ?
 
H

Herby

I tried just declaring a global instance and now get the following
error

error C3145: 'flowControlStack' : global or static variable may not
have managed type FlowControlStack
 
M

Marcus Heege

In theory, you could also use the code below, ....

#include <msclr/gcroot.h>

msclr::gcroot<FlowControlStack> g_fcs;

.... but I would prefer a static variable of a managed class instead.

Marcus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top