Solved

Module level variables and locking

Posted on 2002-03-27
7
154 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
  • 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now