SlideShare a Scribd company logo
4
Most read
6
Most read
8
Most read
Operating System 22
Threading Issues
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
Threading Issues
• Semantics of fork() and exec() system
calls
• Signal handling
– Synchronous and asynchronous
• Thread cancellation of target thread
– Asynchronous or deferred
• Thread-local storage
• Scheduler Activations
Semantics of fork() and exec()
• Does fork()duplicate only the
calling thread or all threads?
– Some UNIXes have two versions of fork
• exec() usually works as normal –
replace the running process
including all threads
Signal Handling
n Signals are used in UNIX systems to notify a
process that a particular event has occurred.
n A signal handler is used to process signals
1. Signal is generated by particular event
2. Signal is delivered to a process
3. Signal is handled by one of two signal handlers:
1. default
2. user-defined
n Every signal has default handler that kernel
runs when handling signal
l User-defined signal handler can override default
l For single-threaded, signal delivered to process
Signal Handling (Cont.)
n Where should a signal be delivered
for multi-threaded?
l Deliver the signal to the thread to
which the signal applies
l Deliver the signal to every thread in the
process
l Deliver the signal to certain threads in
the process
l Assign a specific thread to receive all
signals for the process
Thread Cancellation
• Terminating a thread before it has finished
• Thread to be canceled is target thread
• Two general approaches:
– Asynchronous cancellation terminates the
target thread immediately
– Deferred cancellation allows the target thread
to periodically check if it should be cancelled
• Pthread code to create and cancel a thread:
Thread Cancellation (Cont.)
• Invoking thread cancellation requests cancellation, but
actual cancellation depends on thread state
• If thread has cancellation disabled, cancellation remains
pending until thread enables it
• Default type is deferred
– Cancellation only occurs when thread reaches cancellation
point
• I.e. pthread_testcancel()
• Then cleanup handler is invoked
• On Linux systems, thread cancellation is handled through
signals
Thread-Local Storage
• Thread-local storage (TLS) allows each
thread to have its own copy of data
• Useful when you do not have control
over the thread creation process (i.e.,
when using a thread pool)
• Different from local variables
– Local variables visible only during single
function invocation
– TLS visible across function invocations
• Similar to static data
– TLS is unique to each thread
Scheduler Activations
• Both M:M and Two-level models require
communication to maintain the appropriate
number of kernel threads allocated to the
application
• Typically use an intermediate data structure
between user and kernel threads –
lightweight process (LWP)
– Appears to be a virtual processor on which
process can schedule user thread to run
– Each LWP attached to kernel thread
– How many LWPs to create?
• Scheduler activations provide upcalls - a
communication mechanism from the kernel to
the upcall handler in the thread library
• This communication allows an application to
maintain the correct number kernel threads
Operating System Examples
• Windows Threads
• Linux Threads
Windows Threads
• Windows implements the Windows API –
primary API for Win 98, Win NT, Win 2000,
Win XP, and Win 7
• Implements the one-to-one mapping, kernel-
level
• Each thread contains
– A thread id
– Register set representing state of processor
– Separate user and kernel stacks for when thread
runs in user mode or kernel mode
– Private data storage area used by run-time
libraries and dynamic link libraries (DLLs)
• The register set, stacks, and private storage
area are known as the context of the thread
Windows Threads (Cont.)
• The primary data structures of a thread
include:
– ETHREAD (executive thread block) –
includes pointer to process to which thread
belongs and to KTHREAD, in kernel space
– KTHREAD (kernel thread block) – scheduling
and synchronization info, kernel-mode
stack, pointer to TEB, in kernel space
– TEB (thread environment block) – thread id,
user-mode stack, thread-local storage, in
user space
Windows Threads Data Structures
Linux Threads
• Linux refers to them as tasks rather than threads
• Thread creation is done through clone() system call
• clone() allows a child task to share the address space
of the parent task (process)
– Flags control behavior
• struct task_struct points to process data
structures (shared or unique)
Assignment
• Explain any two issues related to thread
management.

More Related Content

PPTX
Semophores and it's types
PPTX
CPU Scheduling in OS Presentation
PPT
Os Threads
PPT
File access methods.54
PPTX
Directory implementation and allocation methods
PPT
Chapter 10 - File System Interface
PPTX
Inter Process Communication
PPT
Os Swapping, Paging, Segmentation and Virtual Memory
Semophores and it's types
CPU Scheduling in OS Presentation
Os Threads
File access methods.54
Directory implementation and allocation methods
Chapter 10 - File System Interface
Inter Process Communication
Os Swapping, Paging, Segmentation and Virtual Memory

What's hot (20)

PPTX
Compiler Design Unit 4
PDF
Run time storage
PPTX
Thread scheduling in Operating Systems
PPTX
Memory management ppt
PDF
Deadlock Avoidance - OS
PPTX
Deadlock Prevention
ODP
Unix Memory Management - Operating Systems
PPTX
Graph coloring using backtracking
PPTX
Linux process management
PPT
Ipc in linux
PPTX
DBMS - RAID
PPTX
Page replacement algorithms
PPTX
Linux file system
PPTX
Threads and multi threading
PPTX
Kernel module in linux os.
PPT
Operating Systems Process Scheduling Algorithms
PDF
Distributed deadlock
PPTX
Context switching
PDF
Multithreading
Compiler Design Unit 4
Run time storage
Thread scheduling in Operating Systems
Memory management ppt
Deadlock Avoidance - OS
Deadlock Prevention
Unix Memory Management - Operating Systems
Graph coloring using backtracking
Linux process management
Ipc in linux
DBMS - RAID
Page replacement algorithms
Linux file system
Threads and multi threading
Kernel module in linux os.
Operating Systems Process Scheduling Algorithms
Distributed deadlock
Context switching
Multithreading
Ad

Similar to Operating system 22 threading issues (20)

PDF
Multithreaded Programming Part- III.pdf
PDF
Ch4 threads
PPT
Threads in Operating systems and concepts
PDF
Threads operating system slides easy understand
PPT
Ch04 threads
PDF
The Thread Chapter 4 of Operating System
PPT
Threads Advance in System Administration with Linux
PDF
Multithreaded Programming in oprating system
PPTX
Networking threads
PPTX
PPT
Chapter 4 - Threads
PDF
threads (1).pdfmjlkjfwjgliwiufuaiusyroayr
PPT
Operating System 4
PPT
Operating System 4 1193308760782240 2
PPT
Ch4 Threads
PPTX
Threads, signal and socket system calls.pptx
PDF
Thread
PDF
CH04.pdf
PPTX
Chapter 4 - Operating Systems Threads.pptx
PDF
Sucet os module_2_notes
Multithreaded Programming Part- III.pdf
Ch4 threads
Threads in Operating systems and concepts
Threads operating system slides easy understand
Ch04 threads
The Thread Chapter 4 of Operating System
Threads Advance in System Administration with Linux
Multithreaded Programming in oprating system
Networking threads
Chapter 4 - Threads
threads (1).pdfmjlkjfwjgliwiufuaiusyroayr
Operating System 4
Operating System 4 1193308760782240 2
Ch4 Threads
Threads, signal and socket system calls.pptx
Thread
CH04.pdf
Chapter 4 - Operating Systems Threads.pptx
Sucet os module_2_notes
Ad

More from Vaibhav Khanna (20)

PPTX
Information and network security 47 authentication applications
PPTX
Information and network security 46 digital signature algorithm
PPTX
Information and network security 45 digital signature standard
PPTX
Information and network security 44 direct digital signatures
PPTX
Information and network security 43 digital signatures
PPTX
Information and network security 42 security of message authentication code
PPTX
Information and network security 41 message authentication code
PPTX
Information and network security 40 sha3 secure hash algorithm
PPTX
Information and network security 39 secure hash algorithm
PPTX
Information and network security 38 birthday attacks and security of hash fun...
PPTX
Information and network security 37 hash functions and message authentication
PPTX
Information and network security 35 the chinese remainder theorem
PPTX
Information and network security 34 primality
PPTX
Information and network security 33 rsa algorithm
PPTX
Information and network security 32 principles of public key cryptosystems
PPTX
Information and network security 31 public key cryptography
PPTX
Information and network security 30 random numbers
PPTX
Information and network security 29 international data encryption algorithm
PPTX
Information and network security 28 blowfish
PPTX
Information and network security 27 triple des
Information and network security 47 authentication applications
Information and network security 46 digital signature algorithm
Information and network security 45 digital signature standard
Information and network security 44 direct digital signatures
Information and network security 43 digital signatures
Information and network security 42 security of message authentication code
Information and network security 41 message authentication code
Information and network security 40 sha3 secure hash algorithm
Information and network security 39 secure hash algorithm
Information and network security 38 birthday attacks and security of hash fun...
Information and network security 37 hash functions and message authentication
Information and network security 35 the chinese remainder theorem
Information and network security 34 primality
Information and network security 33 rsa algorithm
Information and network security 32 principles of public key cryptosystems
Information and network security 31 public key cryptography
Information and network security 30 random numbers
Information and network security 29 international data encryption algorithm
Information and network security 28 blowfish
Information and network security 27 triple des

Recently uploaded (20)

PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Transform Your Business with a Software ERP System
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Essential Infomation Tech presentation.pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
medical staffing services at VALiNTRY
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Nekopoi APK 2025 free lastest update
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
System and Network Administraation Chapter 3
Adobe Illustrator 28.6 Crack My Vision of Vector Design
How to Migrate SBCGlobal Email to Yahoo Easily
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Transform Your Business with a Software ERP System
Upgrade and Innovation Strategies for SAP ERP Customers
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Essential Infomation Tech presentation.pptx
Design an Analysis of Algorithms II-SECS-1021-03
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
medical staffing services at VALiNTRY
How Creative Agencies Leverage Project Management Software.pdf
Understanding Forklifts - TECH EHS Solution
Nekopoi APK 2025 free lastest update
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Odoo Companies in India – Driving Business Transformation.pdf
System and Network Administraation Chapter 3

Operating system 22 threading issues

  • 1. Operating System 22 Threading Issues Prof Neeraj Bhargava Vaibhav Khanna Department of Computer Science School of Engineering and Systems Sciences Maharshi Dayanand Saraswati University Ajmer
  • 2. Threading Issues • Semantics of fork() and exec() system calls • Signal handling – Synchronous and asynchronous • Thread cancellation of target thread – Asynchronous or deferred • Thread-local storage • Scheduler Activations
  • 3. Semantics of fork() and exec() • Does fork()duplicate only the calling thread or all threads? – Some UNIXes have two versions of fork • exec() usually works as normal – replace the running process including all threads
  • 4. Signal Handling n Signals are used in UNIX systems to notify a process that a particular event has occurred. n A signal handler is used to process signals 1. Signal is generated by particular event 2. Signal is delivered to a process 3. Signal is handled by one of two signal handlers: 1. default 2. user-defined n Every signal has default handler that kernel runs when handling signal l User-defined signal handler can override default l For single-threaded, signal delivered to process
  • 5. Signal Handling (Cont.) n Where should a signal be delivered for multi-threaded? l Deliver the signal to the thread to which the signal applies l Deliver the signal to every thread in the process l Deliver the signal to certain threads in the process l Assign a specific thread to receive all signals for the process
  • 6. Thread Cancellation • Terminating a thread before it has finished • Thread to be canceled is target thread • Two general approaches: – Asynchronous cancellation terminates the target thread immediately – Deferred cancellation allows the target thread to periodically check if it should be cancelled • Pthread code to create and cancel a thread:
  • 7. Thread Cancellation (Cont.) • Invoking thread cancellation requests cancellation, but actual cancellation depends on thread state • If thread has cancellation disabled, cancellation remains pending until thread enables it • Default type is deferred – Cancellation only occurs when thread reaches cancellation point • I.e. pthread_testcancel() • Then cleanup handler is invoked • On Linux systems, thread cancellation is handled through signals
  • 8. Thread-Local Storage • Thread-local storage (TLS) allows each thread to have its own copy of data • Useful when you do not have control over the thread creation process (i.e., when using a thread pool) • Different from local variables – Local variables visible only during single function invocation – TLS visible across function invocations • Similar to static data – TLS is unique to each thread
  • 9. Scheduler Activations • Both M:M and Two-level models require communication to maintain the appropriate number of kernel threads allocated to the application • Typically use an intermediate data structure between user and kernel threads – lightweight process (LWP) – Appears to be a virtual processor on which process can schedule user thread to run – Each LWP attached to kernel thread – How many LWPs to create? • Scheduler activations provide upcalls - a communication mechanism from the kernel to the upcall handler in the thread library • This communication allows an application to maintain the correct number kernel threads
  • 10. Operating System Examples • Windows Threads • Linux Threads
  • 11. Windows Threads • Windows implements the Windows API – primary API for Win 98, Win NT, Win 2000, Win XP, and Win 7 • Implements the one-to-one mapping, kernel- level • Each thread contains – A thread id – Register set representing state of processor – Separate user and kernel stacks for when thread runs in user mode or kernel mode – Private data storage area used by run-time libraries and dynamic link libraries (DLLs) • The register set, stacks, and private storage area are known as the context of the thread
  • 12. Windows Threads (Cont.) • The primary data structures of a thread include: – ETHREAD (executive thread block) – includes pointer to process to which thread belongs and to KTHREAD, in kernel space – KTHREAD (kernel thread block) – scheduling and synchronization info, kernel-mode stack, pointer to TEB, in kernel space – TEB (thread environment block) – thread id, user-mode stack, thread-local storage, in user space
  • 13. Windows Threads Data Structures
  • 14. Linux Threads • Linux refers to them as tasks rather than threads • Thread creation is done through clone() system call • clone() allows a child task to share the address space of the parent task (process) – Flags control behavior • struct task_struct points to process data structures (shared or unique)
  • 15. Assignment • Explain any two issues related to thread management.