Understanding Threads using Visual Basic 2005 - Part 1
page 1 of 7
Published: 02 Jun 2008
In this first part of the series, Abhishek describes the concepts of threading, different procedures to create threads, synchronization among multiple threads, uses of Sleep and Join methods, code locking using SyncLock, and Monitor with sample code in Visual Basic 2005.
by Abhishek Kumar Singh
Average Rating: 
Views (Total / Last 10 Days): 51682/ 72


In terms of kernel scheduling, a process is a heavy unit, whereas a thread is the smallest and lightest unit. Each process reserves its own memory space (i.e. address space) as well as resources. Thread does not specifically own resources except registers and stack.  Each thread has to be a part of at least one process. All threads which are part of single process share the same address space. Overall it means that if we divide a heavy process into multiple threads to execute concurrently (so called multithreading), we can get the result much faster. Thinking like this feels good, but the major responsibility on programmers, which must be known, understood, and applied in multithreaded programs is, thread synchronization, thread communication methodology, safe resource sharing among threads etc. In the following article you will see about these one by one with lots of Visual Basic sample code (with output details) written for better understanding. I have used Visual Basic 2005 for the code examples in this article.

Important Terms to Know About the Threading Model

·         Thread- The smallest unit of program or part of a process, running in the execution area. Several threads can be the part of a single process.

·         Process- An instance of a program. Any single process contains at least one thread.

·         Context switching- A methodology used by the operating system to switch the processor among threads to perform parallel execution by giving time slices to each of them. Context switching between processes is generally slower than context switching between threads.

·         Kernel- Core of operating system, which performs thread instantiation and execution. It provides several system call interface for programmers to deal with threads to customize the execution approach.

·         Multitasking (with multi-core CPU)- A method of operating system in which it shares CPU time among multiple tasks (processes) by switching between them on the basis of some predefined process scheduling algorithms. As we all know, in single CPU machine, in truth, no two processes can run at the same point of time. Multitasking gives a impersonate way to it. But now multi-core CPUs are available in the market by which more than one process can run concurrently depending upon the number of CPU cores. Even single process is divided into sub processes and processed by different CPU cores. In this way multi-core CPUs give better performance.

·         Multithreading- An execution model which allows several threads to execute independently under the context of a single process. Multiple threads can run simultaneously, so called concurrent execution. Threads can share process resources. So it gives faster execution model. In other words we can say that multithreading is "multitasking applied on processes."

View Entire Article

User Comments

Title: Thread   
Name: Pari
Date: 2012-10-16 4:02:22 AM
very helpful
Title: Enginer   
Name: Didier Fonseca
Date: 2010-11-10 4:46:13 PM
Thanks,very good and easy to understand tutorial
Title: dig deeper   
Name: rs
Date: 2008-06-09 10:47:16 AM
nice introduction in synchronization. next thing that comes up comparing different solutions is rating them. how do they differ (e.g. in performance) and which is suitable for what kind of problem ...
Title: thanks   
Name: Abhishek Singh
Date: 2008-06-06 6:50:45 AM
thanks to all of you!
Title: Vey Good Article   
Name: Babita
Date: 2008-06-05 3:23:22 AM
Very useful article about thread.
Title: Good one   
Name: Soumya
Date: 2008-06-03 2:52:33 AM
Very helpful definitions and examples.
Title: nice article   
Name: rupesh
Date: 2008-06-03 2:40:32 AM
Very nice article about thread

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-28 7:10:58 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search