Newsgroup: it.comp.lang.visual-basic
Titolo: [?] riposto la domanda perche imortante - process e thread

scusate se insisto... ma č importante...
La differenza tra "process" e "thread".
Faccio un esempio.
Io apro Internet Explorer, o WinWord. Poi apro/creo un sacco di documenti
(ad es.: piů pagine web, o piů documenti Doc). Ecco, č esatto dire il
process č unico (Internet Explorer o Word), mentre i thread sono tanti
quanti sono i documenti aperti? E qual č un'Api che mi consenta di chiudere
un solo thread lasciando stare gli altri?
Grazie.
Mario

 La differenza tra "process" e "thread".
E' sostanziale:
Un processo è l'insieme delle risorse che un programma necessita per il suo
funzionamento (con il termine risorse intendo memoria fisica e virtuale,
lock di files, ecc.)
Un Thread rappresenta un "pezzo di codice" in esecuzione.
Come potrai facilmente immaginare, ogni processo possiede almeno 1 thread
(altrimenti avremo delle risorse lockkate che non eseguono alcun lavoro!!).
Le applicazioni multitrhead sono dei processi che sono in grado di eseguire
+ threads contemporaneamente, e quindi sono in grado di svolgere più compiti
in parallelo.
In realtà le cose sono un po' più complesse (per es: esistono diversi
modelli di threads) però non mi sembra il caso di dettagliare ulteriormente
la questione.
Sappi che ogni progetto "Standard EXE" di VB6 è costituito da 1 processo e 1
thead, un "ActiveX EXE" può utilizzare 1 processo e 1 thread oppure 1
processo + n thread che fanno parte di uno stesso pool infine un "ActiveX
DLL" supporta 2 modalità di threading: Single Threaded e Apartment Threaded.
Trovi tutte le informazioni del caso su MSDN... ma preparati a GROSSISIME
novità con l'uscita della nuova versione di VB (chiamata per ora Next
Generation), la quale supporterà nuovi modelli di Threading come il Free
Threaded....
--
Lorenzo Benaglia
24 Ore Personal Finance S.p.A.
Milano
Italy

un solo thread lasciando stare gli altri?
PostThreadMessage, con il messaggio WM_QUIT
Oppure (ma non ho il mio caro Visualizzatore API per controllare :(
(mi sento disarmato)) KillThread o TerminateThread, ma non ti
garantisco che il thread ucciso non trascini con sè nella tomba anche
tutti i "compagni di squadra" ^___^

grazie 1000 a tutti.

 Grazie.
Ciao Mario,
conosci l'inglese? Ti posto le prime righe in merito prese dalla Win32
Programmer's Reference:
(se te le traducessi al volo rischierei di tralasciare nozioni importanti o
di non riuscire a rendere pienamente il significato ed i legami che
intercorrono tra i diversi aspetti di questo argomento - considerando anche
che due dritte pratiche le hai già ricevute).
Processes and Threads
An application written for Microsoft® Windows® consists of one or more
processes. A process, in the simplest terms, is an executing program. One or
more threads run in the context of the process. A thread is the basic unit
to which the operating system allocates processor time. A thread can execute
any part of the process code, including parts currently being executed by
another thread.
About Processes and Threads
Each process provides the resources needed to execute a program. A process
has a virtual address space, executable code, data, object handles,
environment variables, a base priority, and minimum and maximum working set
sizes. Each process is started with a single thread, often called the
primary thread, but can create additional threads from any of its threads.
All threads of a process share its virtual address space and system
resources. In addition, each thread maintains exception handlers, a
scheduling priority, and a set of structures the system will use to save the
thread context until it is scheduled. The thread context includes the
thread's set of machine registers, the kernel stack, a thread environment
block, and a user stack in the address space of the thread's process.
Multitasking
A multitasking operating system divides the available processor time among
the processes or threads that need it. Windows is designed for preemptive
multitasking; it allocates a processor time slice to each thread it
executes. The currently executing thread is suspended when its time slice
elapses, allowing another thread to run. When the system switches from one
thread to another, it saves the context of the preempted thread and restores
the saved context of the next thread in the queue.
Advantages of Multitasking
To the application developer, the advantage of multitasking is the ability
to create applications that use more than one process and to create
processes that use more than one thread of execution. For example, a process
can have a user interface thread that manages interactions with the user
(keyboard and mouse input), and worker threads that perform other tasks
while the user interface thread waits for user input. If you give the user
interface thread a higher priority, the application will be more responsive
to the user, while the worker threads use the processor efficiently during
the times when there is no user input.
When to Use Multitasking
There are two ways to implement multitasking: as a single process with
multiple threads or as multiple processes, each with one or more threads. An
application can put each thread that requires a private address space and
private resources into its own process, to protect it from the activities of
other process threads.
A multithreaded process can manage mutually exclusive tasks with threads,
such as providing a user interface and performing background calculations.
Creating a multithreaded process can also be a convenient way to structure a
program that performs several similar or identical tasks concurrently. For
example, a named pipe server can create a thread for each client process
that attaches to the pipe. This thread manages the communication between the
server and the client. Your process could use multiple threads to accomplish
the following tasks:
· Manage input for multiple windows.
· Manage input from several communications devices.
· Distinguish tasks of varying priority. For example, a high-priority thread
manages time-critical tasks, and a low-priority thread performs other tasks.
· Allow the user interface to remain responsive, while allocating time to
background tasks.
It is typically more efficient for an application to implement multitasking
by creating a single, multithreaded process, rather than creating multiple
processes, for the following reasons:
· The system can perform a context switch more quickly for threads than
processes, because a process has more overhead than a thread does (the
process context is larger than the thread context).
· All threads of a process share the same address space and can access the
process's global variables, which can simplify communication between
threads.
· All threads of a process can share open handles to resources, such as
files and pipes.
[...]
Spero che ti servano per "iniziare" ad approfondire l'argomento.
Ciao.
--
Princi, 
princ...@programmer.net
--------------------------------------------------------------------------
"Tutti sanno che una cosa è impossibile da realizzare,
finché arriva uno sprovveduto che non lo sa e la inventa." A.E.


VB7 avra' i thread gratis? VB5 li aveva a caro prezzo, VB6 a peso d'oro (non
dovevi mai generare un errore, pena l'autodistruzione della macchina :)),
c'e' stata un'inversione di tendenza? :)
Ciaotutti,
Alessandro


 VB7 avra' i thread gratis?
si', ma dovrai comprare da ms i processi, per i quali a redmond si stanno a
buon conto facendo un'esperienza suprema...