21
Threading Models in Visual Basic Language Student Name: Danyu Xu Student ID:98044

Threading Models in Visual Basic Language Student Name: Danyu Xu Student ID:98044

Embed Size (px)

Citation preview

Threading Models in Visual Basic Language

Student Name: Danyu Xu

Student ID:98044

Process/ThreadProcess Execution of an individual

program 3 Components

- An executable program- Associated data needed by the Program

-Execution by the ProgramAll information the O/S

needs to manage the process

Thread A dispatchable unit of

work An execution

state(running,ready,etc.)

Some per-thread static storage for local variables

Access to the memory and resources of its process

Benefits of a Thread Less time to create a new thread than

a process Less time to terminate than a process Less time to switch between two

threads within the same process Since threads within the same process

share same files and memory, they can communicate with each other without invoking the kernel

COM(Component Object Model) in Visual Basic

a software architecture that allows applications to be built from binary software components.

the underlying architecture that forms the foundation for higher-level software services , eg. OLE, ActiveX.

COM(Component Object Model) in Visual Basic

(Continued) A mechanism for keeping track of

whether an object is in use and deleting it when no longer needed.

A standard error-reporting mechanism and set of error codes and values.

A mechanism for apps to exchange objects.

In-Process Server Component in VB-DLL

In-Process are always DLL (dynamic link libraries) files.

DLL-A library containing API functions or procedures accessible to and called from an application.

-ideal for implementing standard objects to reuse or share among apps.

-ideal for defining interfaces implemented by other objects.

-preferred to create high-performance objects without a user interface.

In-Process Server Component in VB-DLL

(Continued)

-Windows API(Application Programming Interface) has a collection of functions and procedures stored in Dynamic-Link Libraries.

Out-of-Process Server Component

Out-of-Process are always EXE (executable) files.

-objects can execute in their own thread.

-objects can be created and used both by client applications and by running the server as a standalone app.

Difference Between DLL and EXE

The way Windows interacts with them

Memory Organization of 16-bit OS

Code for DLL A Data for DLL ACode for EXE B Data for EXE BCode for EXE A Data for EXE B-windows 3.x-if a program accidentally modifies another

program’s memory, can bring down the system.

-Every application has one and only one thread.

Memory Organization of 32-bit OS

Code for EXE A Code for DLL AData for EXE A Data for DLL A===============Code for DLL AData for DLL ACode for EXE AData for EXE A--process space – the memory app runs in--walled off from other app--lower level physical memory is sharedWinNT Each object could have its own thread, or the app ;might have a fixes number

of threads and could manage its objects across the threads.

Communications Between Apps Under 32-bit OS

Mechanism of Marshalling Proxy object – fake object exposes same interface as the actual

object.-created by OLE. Types of Marshalling:--Between Apps--Between networks(DCOM,overhead of marshalling

function calls is negligible compared to transfer of large amount of data)

Features of In-Process and Out-of-Process server

• EXE -It can run as a stand-alone application apart

from the client-does not share same address space under

the OS.• DLL-server component and client share some of

the same memory.- share the same executable space.

Features of In-Process and Out-of-Process Server

(Continued) Performance --In-Process server shares the same process space

with its client at run time--server and client share some of the same memory.--Public Creatable classes can be instantiated only

as MultiUse objects. FlexibilityOut-of-Process server provide classes either

SingleUse or MultiUse

Threading Models Apartment Threading Model

(single threaded apartments) Free Threading Model (multi

threaded apartments) Thread Neutral Apartment

Model

Apartment Threading Model

A “logical container” that

-creates an association between objects and, in some cases, threads.

-a set of rules programmers must obey to receive the concurrency behavior they expect from COM environment.

-system-supplied code that helps programmers manage thread concurrency with respect to COM objects.

-object in each thread is unaware of objects in other threads and has its own separate copy of global data.

SingleUse/MultiUse A SingleUse Class

can only supply one instance of itself

One Instance – one server component

A MultiUse class can supply more than one instance of itself per copy of its component.

One server component – many instance

SingleUse/MultiUse

(Continued) Cons:high overhead Pros:avoid blocking

Blocking - >1 user try to call the same code at the same time.

Single-threaded apartment (STA)

a set of COM objects associated with a particular thread.

a place where an object or a proxy "lives."

Multi-Threaded Apartment (MTA)

a set of COM objects associated with a set of threads in the process such that any thread can call any object implementation directly without the interposition of system code.

Thread Neutral Apartment Model

MTS