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

Threading Models in Visual Basic Language

  • Upload
    ciro

  • View
    40

  • Download
    0

Embed Size (px)

DESCRIPTION

Threading Models in Visual Basic Language. Student Name: Danyu Xu Student ID:98044. Process Execution of an individual program 3 Components - An executable program - Associated data needed by the Program -Execution by the Program All information the O/S needs to manage the process. - PowerPoint PPT Presentation

Citation preview

Page 1: Threading Models in Visual Basic Language

Threading Models in Visual Basic Language

Student Name: Danyu XuStudent ID:98044

Page 2: Threading Models in Visual Basic Language

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

Page 3: Threading Models in Visual Basic Language

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

Page 4: Threading Models in Visual Basic Language

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.

Page 5: Threading Models in Visual Basic Language

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.

Page 6: Threading Models in Visual Basic Language

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.

Page 7: Threading Models in Visual Basic Language

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.

Page 8: Threading Models in Visual Basic Language

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.

Page 9: Threading Models in Visual Basic Language

Difference Between DLL and EXE

The way Windows interacts with them

Page 10: Threading Models in Visual Basic Language

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.

Page 11: Threading Models in Visual Basic Language

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.

Page 12: Threading Models in Visual Basic Language

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)

Page 13: Threading Models in Visual Basic Language

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.

Page 14: Threading Models in Visual Basic Language

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

Page 15: Threading Models in Visual Basic Language

Threading Models Apartment Threading Model

(single threaded apartments) Free Threading Model (multi

threaded apartments) Thread Neutral Apartment

Model

Page 16: Threading Models in Visual Basic Language

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.

Page 17: Threading Models in Visual Basic Language

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

Page 18: Threading Models in Visual Basic Language

SingleUse/MultiUse(Continued) Cons:high overhead Pros:avoid blockingBlocking - >1 user try to call the same

code at the same time.

Page 19: Threading Models in Visual Basic Language

Single-threaded apartment (STA)

a set of COM objects associated with a particular thread.

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

Page 20: Threading Models in Visual Basic Language

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.

Page 21: Threading Models in Visual Basic Language

Thread Neutral Apartment Model

MTS