7-1 JMH Associates © 2003, All rights reserved Designing and Developing Reliable, Scaleable Multithreaded Windows Applications Chapter 10 Supplement Advanced.

Slides:



Advertisements
Similar presentations
Lesson 12: Kernel-mode Thread Sync (aka: Why I love Gentoo)
Advertisements

Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Threads.
1 Chapter 5 Threads 2 Contents  Overview  Benefits  User and Kernel Threads  Multithreading Models  Solaris 2 Threads  Java Threads.
 A quantum is the amount of time a thread gets to run before Windows checks.  Length: Windows 2000 / XP: 2 clock intervals Windows Server systems: 12.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
8-1 JMH Associates © 2004, All rights reserved Windows Application Development Chapter 10 - Supplement Introduction to Pthreads for Application Portability.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for Threads.
1 I/O Management in Representative Operating Systems.
3-1 JMH Associates © 2004, All rights reserved Windows Application Development Chapter 9 Synchronization Performance Impact and Guidelines.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 JMH Associates © 2004, All rights reserved Chapter 15 Asynchronous Input/Output.
Chapter 4: Threads READ 4.1 & 4.2 NOT RESPONSIBLE FOR 4.3 &
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Fundamentals of Python: From First Programs Through Data Structures
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Chapter 4 Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 4 Operating Systems.
Chapter 4: Threads. 4.2 Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Win32 Programming Lesson 13: Thread Pooling (Wow, Java is good for something…)
Today’s Agenda  Quick Review  Finish Java Threads  The CS Problem Advanced Topics in Software Engineering 1.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
1-1 © 2004 JMH Associates. All rights reserved. Windows Application Development Chapter 7 Windows Thread Management.
Multithreaded Programming With the Win32 API Andrew Tucker Andrew Tucker Debugger Development Lead March 13, 1998.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
NT Kernel CS Spring Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching.
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
OS2014 PROJECT 2 Supplemental Information. Outline Sequence Diagram of Project 2 Kernel Modules Kernel Sockets Work Queues Synchronization.

Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads Modified from the slides of the text book. TY, Sept 2010.
Chapter 4: Threads.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS3: Concurrency 3.3. Advanced Windows Synchronization.
Notes on Processes, Context, Context Switching The following slides contain partially quoted statements from various Wikipedia pages.
Win32 Synchronization CS Spring Overview Kernel Synchronization - Spinlocks Executive Synchronization - Dispatcher Objects Wait Operations.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads  Overview  Multithreading Models  Threading Issues  Pthreads.
Window Threads Chapter 7 Windows Thread Management.
Chapter 4 – Thread Concepts
OPERATING SYSTEM CONCEPT AND PRACTISE
Multithreading / Concurrency
Chapter 4 – Thread Concepts
Chapter 4: Threads.
Chapter 4: Multithreaded Programming
Nadeem MajeedChoudhary.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Waiting and Synchronization
Chapter 4: Threads.
Chapter 05. Multithread.
Chapter 4: Threads.
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Chapter 4: Threads.
Chapter 4: Threads.
26.
Chapter 4: Threads.
Chapter 4: Threads.
Presentation transcript:

7-1 JMH Associates © 2003, All rights reserved Designing and Developing Reliable, Scaleable Multithreaded Windows Applications Chapter 10 Supplement Advanced Features

7-2 JMH Associates © 2003, All rights reserved OBJECTIVESOBJECTIVES Upon completion of this chapter, you will be able to:  Utilize asynchronous procedure calls  Cancel threads asynchronously  Send signals to specific threads  Put threads in an alertable wait state  Create and use waitable timers

7-3 JMH Associates © 2003, All rights reserved ContentsContents 1.Asynchronous Procedure Calls 2.Alertable Wait Functions 3.APCs and the Baton Example 4.Waitable Timers 5.Asynchronous I/O Quick Overview 6.Lab Exercise 10-Advanced Features

7-4 JMH Associates © 2003, All rights reserved 1. Asynchronous Procedure Calls Similar to completion routine I/O (not covered)  Also specify the thread where the function is to execute  Caution: One thread directly affects another  >= NT 4.0 DWORD QueueUserAPC ( PAPCFUNC pfnAPC, // APC function // void WINAPI, DWORD arg HANDLE hThread, // thread handle ULONG_PTR dwData // APC param); Non-zero is success – GetLastError does not work here

7-5 JMH Associates © 2003, All rights reserved APC Semantics Queues the APC to the specified thread When the target thread enters an alertable state:  A procedure is removed from its queue  The procedure is executed  It receives the specified parameter A thread enters the alertable state with an “alertable wait”  Indicating that it is safe to execute the APC  Example: SignalOjbectAndWait – Fourth parameter is bAleratble (set to TRUE )  Alertable wait function return WAIT_IO_COMPLETION if an APC was executed (and handle not signaled)

7-6 JMH Associates © 2003, All rights reserved 2. Alertable Wait Functions Options to several wait functions – Usually “Ex” versions DWORD SleepEx( DWORD dwMilliseconds, BOOL bAlertable ); Returns as soon as either:  Timeout expires  If bAlerable is set, and an APC is executed WaitForSingleObjectEx ( …, BOOL bAlertable); WaitForMultipleObjectsEx (…, BOOL bAlertable);

7-7 JMH Associates © 2003, All rights reserved Using APCs A boss thread can force a worker to shutdown orderly  TerminateThread() is not orderly  The APC is executed as soon as it is safe to do so  That is, the thread is in an altertable wait state  The APC:  Cleans up and frees resources  Terminates with _endthreadex (ExitCode) This is “synchronous thread cancellation”  Demonstrated in the lab exercise Orderly asynchronous cancellation not directly supported

7-8 JMH Associates © 2003, All rights reserved 3. APCs and the Baton Example Outline - A different solution than in Chapter 10 - compound  Event limitation: Can’t specify which waiting thread is released  So, all threads are released and test if it is their turn  Only one proceeds  Each waiting thread has its own unique event  Event / thread sequence stored in searchable structure  Such as an STL map  Queue an APC to the correct target thread  Target threads wait with altertable waits

7-9 JMH Associates © 2003, All rights reserved 4. Waitable Timers A type of waitable kernel object >= Win2K Perform tasks periodically or at specified times Create your own timing signal:  Create a timing thread  Thread sets an event after waking from a Sleep Two types:  Synchronization timer: Uses a callback – must be in an alertable wait state  Manual reset notification timer: wait on the timer handle

7-10 JMH Associates © 2003, All rights reserved Waitable Timers HANDLE CreateWaitableTimer( LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManualReset, // Manual reset state LPCTSTR lpTimerName // *timer object name ); The timer is initially inactive but is later activated Named, so they is an OpenWaitableTimer function

7-11 JMH Associates © 2003, All rights reserved Setting the Waitable timer BOOL SetWaitableTimer( HANDLE hTimer, const LARGE_INTEGER *pDueTime, LONG lPeriod, // periodic timer interval PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, BOOL fResume // flag for resume state );

7-12 JMH Associates © 2003, All rights reserved Canceling the Waitable Timer CancelWaitableTimer cancels the last effect of a previous SetWaitableTimer  It will not change the signaled state of the timer  Use another SetWaitableTimer to do that BOOL CancelWaitableTimer( HANDLE hTimer );

7-13 JMH Associates © 2003, All rights reserved 5. Asynchronous I/O Quick Overview Issue I/O (read, write) asynchronously  Supported internally with threads  Opinion: Complex to use  Demos if we have time Two types:  Overlapped I/O – Wait on an event or file handle for I/O completion  Extended I/O – Callback function invoked upon I/O completion  Must be in alertable wait state before the callback is invoked Also: I/O completion ports – Overlapped I/O  Small thread pool, multiple I/Os. Thread assigned on I/O completion

7-14 JMH Associates © 2003, All rights reserved Lab Exercise 10-Advanced Features Modify ThreeStage.c to eliminate the TerminateThread calls, using an APC You will also need to add alertable waits to QueueObj.c ThreeStageCancel.c, QueueObcCancel.c provide a solution

7-15 JMH Associates © 2003, All rights reserved NotesNotes

7-16 JMH Associates © 2003, All rights reserved NotesNotes