Link to home
Start Free TrialLog in
Avatar of sramaswa
sramaswa

asked on

Module level variables and locking

Hello,
  I have a VB dll that has 10 classes. This dll gets calls from the web server(IIS). The dll is developed in VB 6.0 and runs on Win2K.
  I have a common variable declared in the common module(.bas) accessible to all the 10 classes. Since the client calling this dll is going to be a web server, I am expecting a lot of simultaneous calls. This common variable is the main variable to hold the data for the classes to process the business logic. With this kind of set up of a common variable in the dll, I am afraid the response of the dll for calls to each class is going to degrade as this common variable will be mutex locked for call to each class. Am I right in thinking that the calls to each class is going to be processed sysnchronously rather than asynchronously? Is the peformance going to be affected? Should I move the common variable to the individual classes?
Thanks
Siva
Avatar of PaulHews
PaulHews
Flag of Canada image

This is not a problem.  The common or global variable will be visible only to the instance of the object calling on it.  These instances are pooled by IIS 5.
Avatar of sramaswa
sramaswa

ASKER

What if more than one class(Object) in the dll is trying to use the global variable in the .bas file at the same time? Are there going to be as many copies of the global variable as the number of classee(Objects) calling them and each one will be used by each instance of the class separately or there is going to be one common variable with a mutex lock on it? Can you refer me some documents, if you could?
I am not sure what you mean by "These instances are pooled by IIS 5.0"? These are VB dlls that are running on component server. Both IIS and the VB components run on different boxes.
> Are there going to be as many copies of the global variable as the number of classee(Objects)
calling them and each one will be used by each instance of the class separately

This is exactly correct.  There will be no blocking.

Here is an article on threading models.  A VB DLL is Apartment Threaded or Single Threaded.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnproasp2/html/threadingmodel.asp 

Neither Apartment threaded (which is what your DLL should be) nor Single Threaded DLLs will reuse common variables when a new instance is created.

See also, this question for a simple test you can perform:
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11567638
Paul,
   I was looking at your resopnse to the qid 11567638. I saw your comment below
"The link you provided is talking about components (a.k.a. class or useercontrol modules).  It is absolutely
true that each class will be in its own thread, but the standard code modules will not.  The standard
code modules will reside in the same thread as the first class that gets instantiated and VB will then
marshall all function calls from other classes into the first class. "
  Help me understand this. Does it mean that there will be only one copy of my global variable in the .bas file and all objects will access only this variable? If this is the case how is VB taking care of contention issues - two different objects trying to access this variable at the same time? The reason I am asking this question is because my variable is called xmlDoc of type msxml2.domdocument. This holds the entire insurance policy. The business logics are in different classes in the same dll. All the classes use this xmlDoc but with different policies. Each business logic class takes 2 - 3 seconds to run the business rules in it. Within these 2 - 3 seconds of one class processing its policy, what will happen if another call is made by a different class with a different policy?
If the standard module is creatd in the memory space of the first class that calls it, then I believe there will be only one memory address at which xmlDoc is created. What is going to happen to the second simultaneous call to this xmlDoc?
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I made some research too and it does not seem to have any problem.
Thanks
Siva
Happy to help. :) Thanks for the A.