Threads and Thread Synchronization in MFC By Gregory Mortensen CSIS 4330 Advanced Windows Programming.

Slides:



Advertisements
Similar presentations
1 Symbian Client Server Architecture. 2 Client, who (a software module) needs service from service provider (another software module) Server, who provide.
Advertisements

The eCos real-time operating system an open source tool to create embedded kernels and applications.
Multi-core Programming Programming with Posix Threads.
Chapter 14 Multithreading Yingcai Xiao. Multithreading is a mechanism for performing two or more tasks concurrently.  In the managed world of the common.
Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
CS 284a, 8 October 1997 Copyright (c) , John Thornley1 CS 284a Lecture Wednesday, 8 October, 1997.
Interfaces. In this class, we will cover: What an interface is Why you would use an interface Creating an interface Using an interface Cloning an object.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
Process Management. External View of the OS Hardware fork() CreateProcess() CreateThread() close() CloseHandle() sleep() semctl() signal() SetWaitableTimer()
Unix Threads operating systems. User Thread Packages pthread package mach c-threads Sun Solaris3 UI threads Kernel Threads Windows NT, XP operating systems.
Chapter 6 Implementing Processes, Threads, and Resources.
Introduction to Microsoft Windows MFC Programming: the Application/Window Approach Lecture 4.
1 I/O Management in Representative Operating Systems.
Threads CNS What is a thread?  an independent unit of execution within a process  a "lightweight process"  an independent unit of execution within.
MFC Workshop: Intro to MFC. What is MFC? Microsoft Foundation Classes C++ wrappers to the Windows SDK An application framework A useful set of extensions.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6.
Tech Talk: DirectDraw Alex Riemann University of Illinois, Urbana-Champaign February 13, 2000.
INTRODUCTION TO VC++ As the Microsoft Windows 3.X and then 5.5 operating system was becoming popular, many programmers were interested in creating graphical.
Recap, Test 1 prep, Composition and Inheritance. Dates Test 1 – 12 th of March Assignment 1 – 20 th of March.
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
Threaded Applications Introducing additional threads in a Delphi application is easy.
Multi-core Programming Programming with Windows Threads.
计算机系 信息处理实验室 Lecture 4 System Mechanisms (2)
Threads and Thread Synchronization Advanced Windows Programming Series 1.
Direct3D Workshop November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals.
1 Confidential Enterprise Solutions Group Process and Threads.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
The Amiga Operating System: Past and Present Aaron Hensley Kayla Zinn Brad Campbell Gregory Mathurin Josh Benson.
GAM666 – Introduction To Game Programming You must use special libraries (aka APIs – application programming interfaces) to make something other than a.
Working in the Background Radan Ganchev Astea Solutions.
Multithreading GSP-420.
OS2014 PROJECT 2 Supplemental Information. Outline Sequence Diagram of Project 2 Kernel Modules Kernel Sockets Work Queues Synchronization.
Multi-core Programming Destroy the Castle Lab 4 Code snippets.
Lecture 121 CS110 Lecture 12 Tuesday, March 9, 2004 Announcements –hw5 due Thursday –Spring break next week Agenda –questions –ArrayList –TreeMap.
Windows Thread Management
GUI-Based Programming ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
System Components ● There are three main protected modules of the System  The Hardware Abstraction Layer ● A virtual machine to configure all devices.
Windows CE Overview and Scheduling Presented by Dai Kawano.
Windows Threading Colin Roby Jaewook Kim.
T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.
Parallel Tools Platform Parallel Debugger Greg Watson Project Leader Greg Watson Project Leader.
Win32 Synchronization CS Spring Overview Kernel Synchronization - Spinlocks Executive Synchronization - Dispatcher Objects Wait Operations.
Threads and Thread Synchronization. Introduction In windows the basic unit of execution is the thread. It is the smallest schedulable unit of execution.
Segments Introduction: slides 3–12 5 minutes—will skip some
Chapter 3: Windows7 Part 5.
Windows Programming Environments
Win32 Threads and Thread Synchronization
Windows and C++11 Threads and Locks
Jim Fawcett CSE681 – Software Modeling & Analysis Fall 2002
Day 12 Threads.
Lecture 7 : Multithread programming
Konstantin Bukin CSE791 – Advanced Windows Programming Summer 2001
Operating Systems: A Modern Perspective, Chapter 6
Threads and Thread Synchronization
Threads and Locks.
Chapter 3: Windows7 Part 5.
Made by Aistė Augustinaitė Software Engineering 3 group
CS1550: Quiz #1 Quiz #1.
Waiting and Synchronization
Asynchronous Programming
Chien-Chung Shen CIS/UD
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/49.
Chapter 2: Operating-System Structures
Implementing Processes, Threads, and Resources
Windows NT History Design Principles System Components
26.
Window Application Development
Microsoft Consumer Channels and Central Marketing Group
Presentation transcript:

Threads and Thread Synchronization in MFC By Gregory Mortensen CSIS 4330 Advanced Windows Programming

User created threads in MFC Worker threads, thin wrapper around win32 API threads. UI or user interface threads have a message map. However UI threads messages are asynchronous from the GUI thread.

Worker threads in MFC Use AfxBeginThread –which calls __begintheadex –does change the parameter list order from the Win32 API CreateThread function –returns a CWinThread pointer –Doesn’t have a message map!

User Interface (UI) threads… Use AfxBeginThread –Which calls __beginthreadex –Which creates a HWND –Cast your UI class (which is inherited from CWinThread) to CRuntimeClass when calling AfxBeginThread, eg AfxBeginThread( RUNTIME_CLASS( yourUIClass ))

User Interface (UI) threads cont. As heretofore mentioned, your UI thread must inherit from CWinThread Must use the macro DECLARE_DYNCREATE in the class declaration Must use the macro IMPLEMENT_DYNCREATE in the class definition WM_QUIT means terminate the thread

Synchronization CCriticalSection CEvent CMutex CSemaphore

Lock Method Lock for Kernal API Objects equates to WaitForSingleObject Lock for CCriticalSection equates to EnterCriticalSection

Unlock CCriticalSection unlock equates to LeaveCriticalSection CMutex unlock equates to ReleaseMutex CSemaphore unlock equates to ReleaseSemaphore, and just as in the API you can release more than one resource at a time CEvent has no Unlock! –Use Set, Reset, or Pulse instead

Multilock Class Same as WaitForMultipleObject You pass in the Multilock class the array of kernel objects and tell it how many there are You can select to wait for all, or wait for one kernel object Eg: –CEvent g_event[4]; –CMultiLock g_mLock(g_event,4); –g_mLock(INFINITE, false);