18.35 15.97.

Slides:



Advertisements
Similar presentations
Process A process is usually defined as an instance of a running program and consists of two components: A kernel object that the operating system uses.
Advertisements

Lesson 12: Kernel-mode Thread Sync (aka: Why I love Gentoo)
CS Lecture 4 Programming with Posix Threads and Java Threads George Mason University Fall 2009.
1 3. Controlling Robot Car by Wireless Sensor The ultimate objective of the project is to control the car motion using the steering wheel The only connection.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
Project 2 教學. Synchronization Functions in Windows HANDLE WINAPI CreateSemaphore ( __in_opt LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, __in LONG lInitialCount,
 Pat Stemen Senior Program Manager Microsoft Corporation PC02.
ISP – 3 rd Recitation “The joy of Windows API” Processes Threads Handles Relevant functions A simple code example.
CS470 Lab 4 TA Notes. Objective Simulate the activities of a producer and consumer – Page 326 Use thread synchronization to solve the producer-consumer.
ISP – 5 th Recitation Mutexes Code example. Mutex Wikipedia definition: Mutual exclusion (often abbreviated to mutex) algorithms are used in concurrent.
7-1 JMH Associates © 2003, All rights reserved Designing and Developing Reliable, Scaleable Multithreaded Windows Applications Chapter 10 Supplement Advanced.
ISP – 4 th Recitation Times System Errors Threads Waits Code examples.
Threads CNS What is a thread?  an independent unit of execution within a process  a "lightweight process"  an independent unit of execution within.
1 JMH Associates © 2004, All rights reserved Chapter 15 Asynchronous Input/Output.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Multithreading.
Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.
1 LiveViz – What is it? Charm++ library Visualization tool Inspect your program’s current state Client runs on any machine (java) You code the image generation.
CSE 380 – Computer Game Programming Render Threading Portal, by Valve,
Chapter 4 Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Win32 Programming Lesson 13: Thread Pooling (Wow, Java is good for something…)
Events and Timers. Event handlers ScratchC#/VS 2 Script == event handler.
Week 3, Day 1: Processes & Threads Return Quiz Processes Threads Lab: Quiz Lab 3: Strategy & Factory Patterns! SE-2811 Slide design: Dr. Mark L. Hornick.
RobotC Advanced Concepts SSI Robotics September 7, 2013 Capitol College.
MultiThreaded Applications. What is Multithreaded Programming? Having your software appear to perform multiple tasks in parallel –Individual paths of.
Win32 Programming Lesson 10: Thread Scheduling and Priorities.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Week 3, Day 1: Processes & Threads Processes Threads SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Lecture 11 Dynamic link libraries. Differences between static libraries and DLLs In static library code is added to the executable. In DLL, the code is.
1-1 © 2004 JMH Associates. All rights reserved. Windows Application Development Chapter 7 Windows Thread Management.
Windows thread programming
Multithreaded Programming With the Win32 API Andrew Tucker Andrew Tucker Debugger Development Lead March 13, 1998.
Programming with POSIX* Threads Intel Software College.
NT Kernel CS Spring Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching.
Multithreading GSP-420.
Multi-core Programming Destroy the Castle Lab 4 Code snippets.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Pthreads #include pthread_t tid ; //thread id. pthread_attr_t attr ; void *sleeping(void *); /* thread routine */ main() { int time = 2 ; pthread_create(&tid,
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
Kyle Marsh Principal Program Manager Microsoft Corporation WCL305.
Win32 Programming Lesson 11: User-mode Thread Sync (aka: How to crash your machine without really trying…)
TinyOS Sandeep Gupta. Operating System (OS) What is an OS? Main functions  Process management  Memory management  Resource management Traditional OSs.
Notes on Processes, Context, Context Switching The following slides contain partially quoted statements from various Wikipedia pages.
Windows Threading Colin Roby Jaewook Kim.
1 Run-to-Completion Non-Preemptive Scheduler. 2 In These Notes... What is Scheduling? What is non-preemptive scheduling? Examples Run to completion (cooperative)
June 11, 2002Serguei A. Mokhov, 1 The Monitor COMP346 - Operating Systems Tutorial 7 Edition 1.2, June 15, 2002.
Lynn Langit Microsoft – Developer Evangelist.
Win32 Synchronization CS Spring Overview Kernel Synchronization - Spinlocks Executive Synchronization - Dispatcher Objects Wait Operations.
CIS NET Applications1 Chapter 8 – Multithreading and Concurrency Management.
pThread synchronization
Tutorial 4. In this tutorial session we’ll see Threads.
03 October, 2007Information System Design IT60105, Autumn 2007 Information System Design IT60105 Lecture 14 Statechart Diagrams.
Window Threads Chapter 7 Windows Thread Management.
Lesson One – Creating a thread
Preemption Set timer interrupts But now, must synchronize Two tools:
Boost String API & Threads
Linux Processes & Threads
Windows Concurrency Concepts and APIs
File Management.
Tech Ed North America /15/2018 4:14 AM Required Slide
null, true, and false are also reserved.
C# Basics These slides are designed for Game Design Class
Waiting and Synchronization
30.
Chapter 05. Multithread.
CSE 451 Autumn 2003 Section 3 October 16.
Windows APIs Some odds and ends Copyright © 1997 – 2016 Curt Hill.
Tutorial 4.
26.
POSIX Threads(pthreads)
Presentation transcript:

void EatBatteryLife() { HANDLE sharedResource = NULL; //spawn multiple threads, one of which does this: while (sharedResource == NULL) { waitTime++; } DO NOT DO THIS

//thread 1's code void UpdateSharedResource() { //set sharedResource sharedResource = UpdateResource(); // Set sharedResourceIsReadyEvent to // signaled SetEvent(sharedResourceIsReadyEvent); } //thread 2's code void ConsumeSharedResource() { DWORD dwWaitResult; dwWaitResult = WaitForSingleObjectEx( sharedResourceIsReadyEvent, INFINITE, FALSE); // indefinite wait switch (dwWaitResult) { case WAIT_OBJECT_0: // // TODO: use sharedResource // break; default: return 0; }

void InitBatteryLifeEaterApp() { timeBeginPeriod(1); //run your whole app } void CleanupBatteryLifeEaterApp() { timeEndPeriod(1); } DO NOT DO THIS

BOOL WINAPI SetWaitableTimerEx( __in HANDLE hTimer, __in const LARGE_INTEGER *lpDueTime, __in LONG lPeriod, __in_opt PTIMERAPCROUTINE pfnCompletionRoutine, __in_opt LPVOID lpArgToCompletionRoutine, __in_opt PREASON_CONTEXT WakeContext, __in ULONG TolerableDelay );

void CreateAndSetPeriodicTimer() { myTimer = CreateWaitableTimerEx(NULL, TimerName,//string with chosen timer name NULL, TIMER_MODIFY_STATE);//required security attribute to call //SetWaitableTimerEx bError = SetWaitableTimerEx(myTimer, DueTime,//UTC due time 10000,//periodic timer duration is ten seconds CompletionRoutinePointer,//APC completion routine ArgsToCompletionRoutine,//completion routine arguments WakeContext,//only if waking the machine 1000);//tolerable delay is one second //DO WORK bError = CancelWaitableTimer(myTimer);//be sure to cancel periodic timers! }

void MyApp::OnInit() { hACDCSource = RegisterPowerSettingNotification(m_hWnd, &GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE); } void MyApp::OnDestroy() { if (hACDCSource != 0) UnregisterPowerSettingNotification(hACDCSource); }

void KeepSystemAwake() { // This example uses a simple, non-localized availablity request diagnostic string POWER_REQUEST_CONTEXT SimpleRqContext; SimpleRqContext.Version = POWER_REQUEST_CONTEXT_VERSION; SimpleRqContext.Flags = POWER_REQUEST_CONTEXT_SIMPLE_STRING; SimpleRqContext.Reason.SimpleReasonString = L“System needed to burn a CD."; HANDLE SimplePowerRequest = PowerCreateRequest(&SimpleRqContext); // Set a system request to prevent automatic sleep PowerSetRequest(SimplePowerRequest,PowerRequestSystemRequired); // // Do work here... // // Clear the request PowerClearRequest(SimplePowerRequest,PowerRequestSystemRequired); }