Solved

Module level variables and locking

Posted on 2002-03-27
7
158 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:sramaswa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 6900033
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.
0
 

Author Comment

by:sramaswa
ID: 6902100
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.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6902471
> 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:
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11567638
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sramaswa
ID: 6902599
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?
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 200 total points
ID: 6902781
The calls to your component are from the Web server.  Say your DLL exposes three objects x, y, z and has one bas module with common variables.

client 1 instantiates object x and calls a method on it.

client 2 instantiates object y and calls a method on it.

The web server will instantiate different threads for the two clients.  No sharing of common data will occur accross thread boundaries....

client 1 instantiates object x and calls a method setting a global variable in the bas module.  Then client 1 instantiates object y and retrieves the value of the variable.  It will have the same value as set in object x, because the webserver maintains the process space for that client, the same as if the DLL was being called by a single client application.  client 2 will not block the application as his instances of the objects are in their own process space.

Component services work on the same lines.  Do the test, you will see for yourself.  Single threaded components can tie up a web server, but not apartment threaded components.
0
 

Author Comment

by:sramaswa
ID: 6903492
I made some research too and it does not seem to have any problem.
Thanks
Siva
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6903662
Happy to help. :) Thanks for the A.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel VBA, find a string in a column, update a cell 7 102
Exit a vb6 apps when a calling it apps closes 15 57
MsgBox 4 71
Advice in Xamarin 21 109
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question