Project 2 教學. Synchronization Functions in Windows HANDLE WINAPI CreateSemaphore ( __in_opt LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, __in LONG lInitialCount,

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)
Multithread API’s Adam Piotrowski Grzegorz Jabłoński Lecture IV.
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.
CS 140 Lecture Notes: Processes and ThreadsSlide 1 UNIX Fork/Exec Example int pid = fork(); if (pid == 0) { exec("foo"); } else { waitpid(pid, &status,
CS444/CS544 Operating Systems Synchronization 2/28/2006 Prof. Searleman
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.
Recitation summary What you should know for the exam
Using the OS. Basic Abstractions Idea Program Result Idea Program Result Program Result … …
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.
CS470 Lab 4 TA Notes. Objective Simulate the activities of a producer and consumer – Page 326 Use thread synchronization to solve the producer-consumer.
CS444/CS544 Operating Systems
CS444/CS544 Operating Systems Synchronization 2/19/2007 Prof. Searleman
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.
ISP – 4 th Recitation Times System Errors Threads Waits Code examples.
Malware Dynamic Analysis Part 3 Veronica Kovah vkovah.ost at gmail See notes for citation1
Threads CNS What is a thread?  an independent unit of execution within a process  a "lightweight process"  an independent unit of execution within.
Multi process-Multi Threaded Amir Averbuch Nezer J. Zaidenberg Amir Averbuch Nezer J. Zaidenberg.
Introduction (Processes and Files)
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.
Multi-core Programming Programming with Windows Threads.
2.3 InterProcess Communication (IPC)
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.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS3: Concurrency 3.4. Windows APIs for Synchronization.
Multithreading GSP-420.
 For an application programmer, the operating system interface is most important  The functions provided by the OS  Abstract resources that are available.
Programming with Windows* Threads Intel Software College.
Synonyms: A _______ is a unit of software that is capable of executing concurrently with other similar units. _______ -- user-defined process in Ada _________.
Threads CSIT 402 Data Structures II. many to oneone to one many to many Multithreading models.
Windows Thread Management
Synchronizing Threads with Semaphores
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.
Unix 教學 1. Unix-like System  Linux  FreeBSD  Solaris  Mac OS X  … 2.
Notes on Processes, Context, Context Switching The following slides contain partially quoted statements from various Wikipedia pages.
Windows Threading Colin Roby Jaewook Kim.
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2.
Win32 Synchronization CS Spring Overview Kernel Synchronization - Spinlocks Executive Synchronization - Dispatcher Objects Wait Operations.
Microsoft TechDayshttp:// Сычев Игорь Microsoft Student Partner.
pThread synchronization
Lecture Lecture 25 Review of Last Lecture DLL’s DLL’s Processes Processes Threads Threads Memory Management Memory Management.
Window Threads Chapter 7 Windows Thread Management.
Process Synchronization
Lecture 7 : Multithread programming
Konstantin Bukin CSE791 – Advanced Windows Programming Summer 2001
Windows Concurrency Concepts and APIs
O.S. Programming Assignment
Using the Operating System
Linux Fork/Exec Example
Windows APIs File Processing Copyright © 2016 Curt Hill.
UNIX Fork/Exec Example
Waiting and Synchronization
30.
Chapter 05. Multithread.
UNIX Fork/Exec Example
class PrintOnetoTen { public static void main(String args[]) {
Linux Fork/Exec Example
26.
Window Application Development
Presentation transcript:

Project 2 教學

Synchronization Functions in Windows HANDLE WINAPI CreateSemaphore ( __in_opt LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, __in LONG lInitialCount, __in LONG lMaximumCount, __in_opt LPCTSTR lpName); EX : The max value for the semaphore Sem is 5, and its initial value is 0 HANDLE Sem; Sem = CreateSemaphore( NULL,0,5,NULL);

Synchronization Functions in Windows DWORD WINAPI WaitForSingleObject ( __in HANDLE hHandle, __in DWORD dwMilliseconds); EX : to wait for a semaphore WaitForSingleObject( Sem, INFINITE );

Synchronization Functions in Windows BOOL WINAPI ReleaseSemaphore ( __in HANDLE hSemaphore, __in LONG lReleaseCount, __out_opt LPLONG lpPreviousCount); EX : to signal a sempahore ReleaseSemaphore(Sem, 1, NULL);

Synchronization Functions in Windows HANDLE WINAPI CreateThread ( __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, __in SIZE_T dwStackSize, __in LPTHREAD_START_ROUTINE lpStartAddress, __in_opt LPVOID lpParameter, __in DWORD dwCreationFlags, __out_opt LPDWORD lpThreadId); EX: to create a thread to execute function ABC CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)ABC, NULL, 0,&ThreadID);

Synchronization Functions in Windows #include 可以使用 Dev-c 或 VC

EX:Hw2 in Windows int main(void) { full=CreateSemaphore( NULL,0,5,NULL); empty=CreateSemaphore( NULL,5,5,NULL); int j, *tid_arg; srand((int)time(0)); printf("start\n"); tid_arg = (int *) malloc(sizeof(int)); *tid_arg = 1; DWORD tid; Thread[0]=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)producer, (void*)tid_arg, 0, &tid); Thread[1]=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)consumer, (void*)tid_arg, 0, &tid); WaitForMultipleObjects(2, Thread, TRUE, INFINITE); system("pause"); return 0; }

EX:Hw2 in Windows void * producer(void *arg) { printf("p_in\n"); int i,tid,in_data; tid = *((int *) arg); free(arg); for (i=0;i<12;i++){ WaitForSingleObject( empty, INFINITE); Sleep(rand()%5); in_data=rand()%256; printf(">>p(%d) =(%d),buf[%d]\n", i, in_data,top); buf[top] = in_data; top=(top+1)%5; ReleaseSemaphore(full, 1, NULL); } return 0; }

EX:Hw2 in Windows void * consumer(void *arg) { printf("c_in\n"); int i,tid,out_data; tid = *((int *) arg); free(arg); for (i=0;i<12;i++){ WaitForSingleObject( full, INFINITE); Sleep(rand()%10); out_data=buf[down]; printf(">>c(%d) =(%d),buf[%d]\n", i, out_data,down); down=(down+1)%5; ReleaseSemaphore(empty, 1, NULL); } return 0; }