[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Question about threading model options in VB 6.0

Posted on 2005-04-20
7
Medium Priority
?
525 Views
Last Modified: 2013-12-04
Hello,

I am programming a VB 6.0 application and I am trying to understand the threading options that are available.

Under the project properties I have a number of options:

(1) Apartment Threaded, (2) Single threaded,  

There are also check boxes for
a) Unattended execution
b) Retained in Memory
c) Upgrade ActiveX controls

This is compiled as an ActiveX dll and I have chosen the "Apartment Threaded Option"

Does this mean that a separate instance of the ActiveX dll memory will be created for each thread that instantiates the object via a "CreateObject" call?  The .dll will be running on one or more multithreaded processes, and each process thread may instantiate one or more of the objects.

Questions

Q1) AM I at risk for a collision and threads walking on each other on the Class Module, or am I protected by the apartment threading properties of having separate data for each thread.

Q2) Am I protected in the module sections of the .dll? The reason I ask this, is that the public variables in the module section appear to be persistent between threads. Is there anything like an "EnterCriticalSection" (similar to  C++) to protect against reentrancy in the module if this is critical?

Q3) Let's say this COM .dll is created by 4 threads in one process and 3 in another: Do I then have 7 separate instantiations of this object?

q4)  Are the module public sections across processes at risk of colliding?

I know this is a complex question, so I am offering 500 points to start. For a great answer, I'll give more!

CSchene

0
Comment
Question by:Christopher Schene
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:Eduard Ghergu
ID: 13832082
"You must turn on the Unattended Execution option and the Retained In Memory option before compilation to host a Microsoft Visual Basic Enterprise Edition for Windows 6.0 component (Microsoft ActiveX DLL) in a multi-threaded environment, such as Microsoft Transaction Server (Mtx.exe), Internet Information Services (Inetinfo.exe), and COM+ (Dllhost.exe)": http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B307211

 = In conclusion, you have to check these check-boxes only if you plan to use Microsoft Transaction Server (MTS) or COM + in order to create an enterprise level application. =

"When you start a new project the currently registered controls are the only ones available. If you start a VB5 project when the VB6 controls are registered, it will require the VB6 versions of the controls to run. The VB compiler allows you to set an existing project to not upgrade ActiveX controls. If you do not check this option, existing projects will be converted to use the VB6 controls. " : http://www.angelfire.com/biz/rhaminisys/vboledll.html

 = In conclusion, you have to check this check-boxe only if you are using VB 5.0. =

"Single Threaded forces your ActiveX DLL to use a single thread for all its objects, even if the client is multithreaded. If you use Single Threaded on a Multithreaded client, the performance of your application will be degraded due to cross-thread marshaling, which is discussed later in this section. "
"Selecting Apartment Threaded will not guarantee that your ActiveX DLL will use multiple threads. If the client application is single-threaded, then all objects of the ActiveX DLL will be attached to a single thread. If the client application is multithreaded, objects of the ActiveX DLL will be distributed and attached to multiple threads accordingly. Reentrancy rules should be strictly adhered to using this threading model with an ActiveX DLL. "
http://www.geocities.com/SiliconValley/Bridge/2582/ClassF.htm

CreateObject call is used only for late-binding purposes. If you want performance, use "new" operator(ealy-binding).

Q1) What collisions are you affraid from? You wil won't get any collisions between threads when using Apartment model.

Q2) Modules are available (and has visibility) to the whole application. So, you cannot protect them. Try to use classes and define the variables as members.

Q3) Not necessarily. That will depend on COM runtime libraries.

Q4) Yes, if can override very easy a value of a variable declared in a module. (see Answer to Q2).

I hope that answer will help you. If you have more question, please ask.
0
 

Author Comment

by:Christopher Schene
ID: 13833903
Hi,

Thanks for the reply...I need to read the reerences. I'll probably have more questions.

Cschene
0
 

Author Comment

by:Christopher Schene
ID: 13834805
>You must turn on the Unattended Execution option and the Retained In Memory option before compilation to host a >Microsoft Visual Basic Enterprise Edition for Windows 6.0 component (Microsoft ActiveX DLL) in a multi-threaded environ
===========================================

Ok, Are you saying that if I do not check those two boxes that even though I have specified "Aprtment threading" I am still, in effect, single threaded? The program that is invoking my dll IS multithreaded.

>= In conclusion, you have to check these check-boxes only if you plan to use Microsoft Transaction Server (MTS) or COM + >in order to create an enterprise level application. =
==========================
 I am not using those applications, but I am runing in a process control enviroment where I must process parallel transactions through one or more servers. In particular I have a historian server (low priority but lots of data), and hi priority real time process servers...so I think the same principle applies.

++++++++++++++++++++++++++++++++++++
Q2) Modules are available (and has visibility) to the whole application. So, you cannot protect them. Try to use classes and define the variables as members.
================================

Are modules the same within a given process?  I believe I can protect them, if need be, using a semaphore to prevent re-entracy. I believe I could even call a C/C++ .dll from VB if some feature to accomplish the "re-entracy blocking" were not available in VB.  I'd rather not, but this application is extremely critical (runs oil refineries and chemical plants)


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Accepted Solution

by:
Eduard Ghergu earned 1500 total points
ID: 13840637
Hello!
The Apartment model is the best solution for a multithreading COM application.
What kind of transactions do you have to process? Do you have a database behind ? In that case, a good solution is to use, though, the transaction server (MTS) or COM+ if you have Win2K or newer. You have no semaphore mechanism in VB. Also, it's a good ideea to use a C/C++ dll(s) for critical part of application.

There are some changes in COM+ comparing with the old COM. Please have also a look at:
http://www.devx.com/vb2themax/Article/19829
http://www.devx.com/vb2themax/Article/19898/0/page/2
0
 

Author Comment

by:Christopher Schene
ID: 13854186
"What kind of transactions do you have to process? "

I am processing alarming and process variable requests for a DCS (Distributed Control System) process control system.  The DCS systems enable the operators to view and control the plant or process via graphical pictures that represent the plant. These displays are connected to what is, in essence, a real time data base that is typically distributed over as many as 100 or more computers. The displays show the information from this real time database and report system anomalies in the form of  alarms.

These systems are usually highly redundant for the most dangerous processes and will often run  for years without ever being shutdown.  I have upgraded systems where a given node has been running for 3 years or more without ever being shutdown.

When  software is upgraded, for example, one node in a redundant pair will be shutdown and reloaded but the process is still running on the alternate node while the new software is loaded. Once the new load is complete and the data bases synchronized, the other node in the pair is shutdown and reloaded. When this second node is shutdown, the process again fails over to the redundant partner so that the process control is never interrupted during the software upgrade.

A process variable would be something like temperature, pressure, flow rate, tank level, etc. The DCS systems have very stringent alarming and alarm reporting requirements and I am processing information that aggregates alarm and process information and very quickly points the operator/engineer to the source of a problem so they can correct it quickly.

For a large continuous process (oil refinery, chemical plants, etc) a problem that goes uncorrected for even a few minutes can result in a  product, such as premium grade gas, being out of spec for hours or the entire day.


0
 
LVL 10

Expert Comment

by:Eduard Ghergu
ID: 13856215
Thank you for your answer. If you still have any questions, I'll be happy to help you. Thank you, also, for the expert points.
0
 

Author Comment

by:Christopher Schene
ID: 13877848
You are welcome!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

873 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