ISP – 4 th Recitation Times System Errors Threads Waits Code examples.

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.
Real-Time Library: RTX
 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.
Correcting Threading Errors with Intel® Thread Checker for Explicit Threads Intel Software College.
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.
Project 2 教學. Synchronization Functions in Windows HANDLE WINAPI CreateSemaphore ( __in_opt LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, __in LONG lInitialCount,
1 JMH Associates © 2004, All rights reserved Chapter 6 Process Management.
CS 284a, 8 October 1997 Copyright (c) , John Thornley1 CS 284a Lecture Wednesday, 8 October, 1997.
ISP – 3 rd Recitation “The joy of Windows API” Processes Threads Handles Relevant functions A simple code example.
ISP – 7 th Recitation Mid semester!!! Semaphores – reminder Events Code examples.
ISP – 5 th Recitation Mutexes Code example. Mutex Wikipedia definition: Mutual exclusion (often abbreviated to mutex) algorithms are used in concurrent.
ISP – 6 th Recitation What’s void? Pointer to pointer/Array of pointers/Two dimensional array “Random” numbers Semaphores Code examples.
7-1 JMH Associates © 2003, All rights reserved Designing and Developing Reliable, Scaleable Multithreaded Windows Applications Chapter 10 Supplement Advanced.
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.
Windows Threading Colin Roby Jaewook Kim
Win32 Programming Lesson 9: Jobs & Thread Basics.
Win32 Programming Lesson 13: Thread Pooling (Wow, Java is good for something…)
MultiThreaded Applications. What is Multithreaded Programming? Having your software appear to perform multiple tasks in parallel –Individual paths of.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS4: Scheduling and Dispatch 4.2. Windows Processes.
Win32 Programming Lesson 10: Thread Scheduling and Priorities.
Multi-core Programming Programming with Windows Threads.
Thread Synchronization with Semaphores
VB.Net - Exceptions Copyright © Martin Schray
1-1 © 2004 JMH Associates. All rights reserved. Windows Application Development Chapter 7 Windows Thread Management.
1 Confidential Enterprise Solutions Group Process and Threads.
Windows thread programming
Multithreaded Programming With the Win32 API Andrew Tucker Andrew Tucker Debugger Development Lead March 13, 1998.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Module 6: Debugging a Windows CE Image.  Overview Debug Zones IDE Debug Setup IDE Debug Commands Platform Builder Integrated Kernel Debugger Other Debugging.
1 Threads Chapter 11 from the book: Inter-process Communications in Linux: The Nooks & Crannies by John Shapley Gray Publisher: Prentice Hall Pub Date:
Multithreading GSP-420.
System calls for Process management
Programming with Windows* Threads Intel Software College.
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Multithreading in JAVA
Windows Thread Management
Practical Sockets and Threads Derek Weitzel. Windows Threads Concurrent processing Concurrent processing Windows Create Thread Windows Create Thread HANDLE.

Shan Gao Fall 2007 Department of Computer Science Georgia State University.
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
Windows CE Overview and Scheduling Presented by Dai Kawano.
Windows Threading Colin Roby Jaewook Kim.
System calls for Process management Process creation, termination, waiting.
Win32 Synchronization CS Spring Overview Kernel Synchronization - Spinlocks Executive Synchronization - Dispatcher Objects Wait Operations.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
Threads and Thread Synchronization. Introduction In windows the basic unit of execution is the thread. It is the smallest schedulable unit of execution.
Window Threads Chapter 7 Windows Thread Management.
Lesson One – Creating a thread
Threads in C Caryl Rahn.
Copyright ©: Nahrstedt, Angrave, Abdelzaher
Multithreading Tutorial
Principles of Operating Systems Lecture 8
Windows Concurrency Concepts and APIs
O.S. Programming Assignment
Operating Systems Lecture 13.
Made by Aistė Augustinaitė Software Engineering 3 group
Waiting and Synchronization
Multithreading Tutorial
Chapter 05. Multithread.
Multithreading Tutorial
Multithreading Tutorial
Windows APIs Some odds and ends Copyright © 1997 – 2016 Curt Hill.
26.
Presentation transcript:

ISP – 4 th Recitation Times System Errors Threads Waits Code examples

GetProcessTimes() Retrieves time statistics of a process: Syntax : BOOL GetProcessTimes( HANDLE hProcess, FILETIME *CreationTime, FILETIME *ExitTime, FILETIME *KernelTime, FILETIME *UserTime); FILETIME contains a 64-bit value representing the number of 100- nanosecond intervals since January 1, 1601 (UTC).

FileTimeToSystemTime() Converts FILETIME to SYSTEMTIME Syntax : BOOL FileTimeToSystemTime( FILETIME *FileTime, SYSTEMTIME *SystemTime ); FILETIME contains a 64-bit value representing the number of 100- nanosecond intervals since January 1, 1601 (UTC). SYSTEMTIME contains fields of year, month, day, hour, min, etc.

SystemTimeToTzSpecificLocalTime() Convert time from UTC to a different time zone. Syntax : BOOL SystemTimeToTzSpecificLocalTime ( TIME_ZONE_INFORMATION *TimeZone, SYSTEMTIME *UniversalTime, SYSTEMTIME *LocalTime ); TIME_ZONE_INFORMATION contains time zone of interest. It can be NULL if the currently used time zone is needed.

Thread Wikipedia definition: Threads are a way for a program to split itself into two or more simultaneously (or pseudo- simultaneously) running tasks. A thread is contained inside a process and different threads in the same process share some resources while different processes do not. Switching between threads of the same process requires less context switching.

Creating a Thread Creating a new thread Syntax : HANDLE CreateThread( SECURITY_ATTRIBUTES *ThreadAttributes, SIZE_T dwStackSize, THREAD_START_ROUTINE *StartAddress, VOID *Parameter, DWORD dwCreationFlags, DWORD *ThreadId );

Creating a Thread Using CreateThread(): Example : tHandle=CreateThread( NULL,// default security attributes 0,// use default stack size (LPTHREAD_START_ROUTINE) searchDB, // thread function &args,// argument to thread function 0,// use default creation flags &threadID// returns the thread identifier ); RED = Not too relevant for our purposes, can keep it like in this example Green = Interesting stuff we have to understand Note : CreateThread() returns the handle to the thread directly.

WaitForSingleObject() - Reminder WaitForSingleObject() is used for waiting for an object to become “signaled”. Syntax : DWORD WaitForSingleObject( HANDLE hThread, DWORD dwMilliseconds ); Each object has a signaled and non signaled state and for each object the meaning is slightly different and depends on its function. For threads, “Signaled” means that the thread has ended.

WaitForMultipleObjects() WaitForMultipleObjects() is used for waiting for several object to become “signaled”. Syntax : DWORD WaitForMultipleObjects( DWORD nCount, HANDLE *lpHandles, BOOL bWaitAll, DWORD dwMilliseconds ); nCount is a the number of processes we’re waiting for. lpHandles is an array of handles to objects. bWaitAll indicates whether we want to wait for all objects to become signaled or the first one.

WaitForMultipleObjects() dwMilliseconds is a timeout period (in ms): 0 means that WaitForSingleObject() is used for polling the status. INFINITE means that our code is waiting for the object to become signaled, even infinitely. Other values are used as a timeout. If the object is not signaled then wait until signaled or timeout occurs. Return values : 0 – The object is in a signaled state. 102h – Timeout has elapsed, the object is nonsignaled. Note: WaitForMultipleObjects() recieves an array of handles. Handles can be handles to all kinds of objects.

TerminateThread() Brutally closing a thread. Syntax : BOOL TerminateThread( HANDLE hThread, DWORD uExitCode ); Returns 0 if failed, nonzero if successful NOTE : There are far less good reasons to brutally terminate threads than there are to processes!

GetExitCodeThread() Retrieves the exit code of a Thread. Syntax: BOOL GetExitCodeThread( HANDLE hObject, DWORD *lpExitCode ); Note: If the thread is still active, a value of STILL_ACTIVE (259) is returned.

GetLastError() Retrieves the calling thread's last-error code value. The last-error code is maintained on a per-thread basis. Multiple threads do not overwrite each other's last-error code. Syntax: DWORD GetLastError(void); Always call GetLastError() immediately after a relevant function returned with an error. List of all error codes (over 10,000) :