What is multithreading?

Top  Previous  Next

Multithreading is an environment where more than one "thread" of execution can take place at the same time. Without support for multithreading, or more than one "thread" of execution, the programmer will be forced to handle everything in one execution context.

Windows is a multithreaded environment in that many simultanous things can take place at the same time: the email client program can receive an email at the same time as the user is using the spreadsheet program and maybe copying a file all at the same time.


In a VPL program without multithreading, only one thread of execution is automatically started by the RTCU system software:


                         <--- This is where the main thread automatically starts execution.
DebugMsg(message:="Hello from VPL Program");




With multithreading, however, the VPL program can start additional threads of execution by declaring thread-blocks:  



                         <--- This is where the thread "Piper" will start execution.
DebugMsg(message:="Hello from Piper!");



  th : Piper;                <--- This declares an instance of the thread "Piper".
th();                                <--- This is where the thread "Piper" is started.
DebugMsg(message:="Hello from main!");



The output of the the multithreaded program above will therefore be:


Hello from main!

Hello from piper!


**** OR:


Hello from piper!

Hello from main!



The order of the execution cannot be predicted as the two threads execute concurrently.



Please continue reading the section Why use multithreading?