1. Thread Class: Use the System.Threading.Thread class to create threads.
2. Thread Constructor: Pass a ThreadStart delegate or a ParameterizedThreadStart delegate to the constructor.
3. ThreadStart Delegate: Represents the method to be executed by the thread.
Example:
using System.Threading;
class Program
{
static void Main()
{
Thread thread = new Thread(new ThreadStart(MyMethod));
thread.Start();
}
static void MyMethod()
{
Console.WriteLine("Thread is running.");
}
}
Processes-
1. Independent units of execution
2. Own memory space (virtual address space)
3. Created by operating system
4. Communicate through Inter-Process Communication (IPC) mechanisms
Threads
1. Lightweight processes
2. Share memory space with parent process
3. Created by process
4. Execute concurrently with other threads
Key Differences
1. Memory: Processes have separate memory, threads share memory
2. Creation: Processes created by OS, threads created by process
3. Communication: Processes use IPC, threads share memory
4. Resources: Processes have own resources, threads share resources
Thread Types
1. User-Level Threads (ULT)
2. Kernel-Level Threads (KLT)
3. Hybrid Threads
Process Communication
1. Pipes
2. Sockets
3. Shared Memory
4. Message Queues
Process Scheduling
1. First-Come-First-Served (FCFS)
2. Shortest Job First (SJF)
3. Priority Scheduling
4. Round Robin (RR)
5. Multi-Level Feedback Queue (MLFQ)
Thread Scheduling
1. Preemptive Scheduling
2. Non-Preemptive Scheduling
3. Time-Slicing
Comments
Post a Comment