7. Concurrency. Motivation Infrastructure Faking concurrency Mobile Java implementation Symbian OS implementation. Maemo implementation Summary

Size: px
Start display at page:

Download "7. Concurrency. Motivation Infrastructure Faking concurrency Mobile Java implementation Symbian OS implementation. Maemo implementation Summary"

Transcription

1 7. Concurrency Motivation Infrastructure Faking concurrency Mobile Java implementation Symbian OS implementation Threads Active objects Maemo implementation Summary 1

2 Motivation Mobile devices are fundamentally reactive systems Incoming events from the environment that require a response Event handler based design commonly applied In addition to user-initiated GUI events, also other environment (constituted by associated auxiliary subsystems) can generate events Nondeterministic event generation No order can be assumed or imposed on executions To be handled with standard facilities of concurrent programming at some level However, why to reveal unnecessary complications to an application developer? 2

3 Content and goals Motivation Infrastructure Faking concurrency Mobile Java implementation Symbian OS implementation Threads Active objects Maemo implementation Summary 3

4 Infrastructure for Concurrent Programming Threads as units of execution, processes as units of resource reservation Pre-emptive vs. non-pre-emptive scheduling Cost of a context switch Thread communication Shared memory Message passing Blocking other threads Crititical regions Protected with semaphores, locks, monitors, etc. 4

5 Design challenges Classic Race conditions (timing changes behavior) Mutual exclusion (not accessing at the same time) Synchronization (acting in synchrony) Parallel slowdown (communication slows down actual work) Practical Complex debugging; errors may be unrepeatable Low-level differences are extensive in different setups Portability in general is hardened when system specifics are relied on Implementation differences can produce different results due to numerous side-effects 5

6 Content and goals Motivation Infrastructure Faking concurrency Mobile Java implementation Symbian OS implementation Threads Active objects Maemo implementation Summary 6

7 From threading to eventing Principle: Make all synchronous requests asyncronous (threads will not wait for immediate return) Messages/shared variables used as the means of communication When all requests have been made, enter a mainloop where incoming messages (or semaphores or lock variables or... ) indicate an event Serve the incoming event with a single thread and wait for the next to come in No need for application level concurrency Internals may still require concurrent processing, but this is not revealed at application level 7

8 Overview Events Events Event-handling thread reads ready to execute (synchronous) service Event handler code 8

9 Event-driven Execution Keyboard Screen Device IF UI mgr App key_press key_press draw draw_fig draw_char 9

10 Serialization of execution instead of real threads Positive In line with non-pre-emptive event processing; events invoke other events which invoke other events No need to consider critical regions as long as events are self- contained Less potential for design and programming errors Simplified implementation in terms of memory consumption Eased porting; operating systems native threads can behave differently but event handler scheme is probably similar in all implementations Negative Event handling interruptions for higher-priority tasks more complicated or impossible Execution priority based on thread priority Possibility to select the highest-priority event Design Visible to the designer or included in the infrastructure 10

11 Content and goals Motivation Infrastructure Faking concurrency Mobile Java implementation Symbian OS implementation Threads Active objects Maemo implementation Summary 11

12 Threading in Virtual Machine Operating system specific threading Operating system handles scheduling Performance can be better (several threads can get more execution time than one thread running the virtual machine) Porting complexitites (different operating systems can have different threading systems, requires intimate connection with Java runtime) Virtual machine implemented threading (green threads) Virtual machine handles scheduling Performance loss Eased porting; especially exceptions and cleanup etc. Essentially an event processing machine, where threads are executed for X instructions per activation peridic event handling Multi-application VM introduces also issues related to securing applications from one another 12

13 Example: Java Threading <<Runnable>> IncrementerThread public int i; // shared incrementsharedvalue start read <<MIDlet>> <<CommandListener>> MyThread 13

14 Example Code public class IncrementerThread extends Thread { public int i; public IncrementerThread() { i = 0; Thread t = new Thread(this); t.start(); } } public void run() { for(;;) i++; } 14

15 Example Code import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class MyThread extends MIDlet implements CommandListener { private Command exitcommand, togglecommand; private TextBox tb; private IncrementerThread t; public MyThread() { exitcommand = new Command("EXIT", Command.EXIT, 1); togglecommand = new Command("Toggle", Command.OK, 2); t = null; t = null; } 15

16 Example Code protected void startapp() { tb = new TextBox("Thread Example", "Thread was started", 80, 0); tb.addcommand(togglecommand); tb.addcommand(exitcommand); tb.setcommandlistener(this); Display.getDisplay(this).setCurrent(tb); t = new IncrementerThread(); } public void commandaction(command c, Displayable d) { if (c == exitcommand) { destroyapp(false); notifydestroyed(); } else { togglethread(); t.interrupt(); } } 16

17 Example Code protected void destroyapp(boolean u) {} protected void pauseapp() {} private void togglethread() { tb = new TextBox("Thread Example", "Thread run " + t.i + " times", 80, 0); tb.addcommand(togglecommand); tb.addcommand(exitcommand); tb.setcommandlistener(this); Display.getDisplay(this).setCurrent(tb); } // togglethread } // MyThread 17

18 Content and goals Motivation Infrastructure Faking concurrency Mobile Java implementation Symbian OS implementation Threads Active objects Maemo implementation Summary 18

19 Components RThread Used similarly to most other systems Create, kill, etc.... Implementation details seem to be dependant on the used version of the Symbian OS, at least to some extent Shared memory, semaphores, mutexes etc that one would expect to be included Again interfaces can be different from e.g. Unix/Linux Functionally things are somewhat similar 19

20 Example Code TInt i; // Communication variable. void myop() { for(;;) i++; } // Thread function. void MyConsoleL() { LOCAL_D CConsoleBase* console; RThread mythread; // Created thread. console = Console::NewL(_L("Thread"), TSize(KConsFullScreen, KConsFullScreen)); CleanupStack::PushL(console); i = 0; // Shared thread is reset in the beginning. TInt status = mythread.create( _L("TEST THREAD"), // Thread name. (TThreadFunction)myOp, // Called procedure. 0x1000, // Size of stack. 0x1000, // Minimum size of thread's heap. 0x1000, // Maximum size of thread's heap. NULL, // Data to be passed to the thread. EOwnerProcess); // Owned by the current process. 20

21 Example Code console->printf(_l("thread created.\n")); mythread.resume(); // Activates the thread. console->getch(); // Wait for keyboard hit. mythread.kill(-1); // Terminate the thread. console->printf(_l("thread run %d rounds.\n"), i); console->getch(); CleanupStack::Pop(); // Console delete console; console = 0; } 21

22 Content and goals Motivation Infrastructure Faking concurrency Mobile Java implementation Symbian OS implementation Threads Active objects Maemo implementation Summary 22

23 Active Objects and Eventing Events Events Active scheduler (1 per thread) Event handlers ach a separate thread) Event handlers (each an active object) 23

24 Benefits Eased mutual exclusion Memory savings (some bytes vs. some kilobytes) Performance improvement for the overall system Operations in the same active scheduler do not require context switch No overhead of changing the process while an operation is being performed Can be offered as a generic event handler included in e.g. application framework 24

25 Components Active object (CActive or its derivative) Implements operations that will be executed when an event occurs Active scheduler (CActiveScheduler or its derivative) Implements scheduling Selects the active object to call Service providers Introduce operations that take some time and potentially require actions by other parties E.g. timers 25

26 Overview Application Create and Install Active Scheduler 1 2 Create AO, issue request, add to Scheduler 4 Start Scheduler Active scheduler Wait for any req Call AO RunL Active object Activate request function3 set iactive true 6 Service provider Set istatus to Pending Service complete 5 Req completed, reset istatus Cleanup, terminate 7 RunL (redo/quit) 26

27 Example Code LOCAL_D CConsoleBase* console; // Write all messages to this. class CDelayer : public CActive { public: static CDelayer *NewL(); ~CDelayer(); void SetHello(TInt adelay); private: CDelayer(); void ConstructL(); protected: void RunL(); void DoCancel(); private: RTimer itimer; }; // class 27

28 Example Code CDelayer::CDelayer(): CActive(EPriorityStandard) {} void CDelayer::ConstructL() { User::LeaveIfError(iTimer.CreateLocal()); CActiveScheduler::Add(this); // Add this object to the set of active objects. } CDelayer * CDelayer::NewL() { CDelayer * self = new (ELeave) CDelayer(); CleanupStack::PushL(self); self->constructl(); CleanupStack::Pop(); // self return self; } CDelayer::~CDelayer() { Cancel(); // DoCancel implementation requires that destructor calls Cancel itimer.close(); } 28

29 Example Code void CDelayer::SetHello(TInt adelay) { // Nested set operations are forbidden. This is ensured // by IsActive and ASSERT_ALWAYS. ASSERT_ALWAYS(!IsActive(), User::Panic(_L("CDelayedHello"), 1)); // Request for an event after adelay. itimer.after(istatus, adelay); // istatus is a member variable of CActive. SetActive(); // Set this active object active. } void CDelayer::RunL() { _LIT(KTimer, "\ntimer expired"); console->printf(ktimer); // Stop the active scheduler, so the execution can continue. CActiveScheduler::Stop(); } void CDelayer::DoCancel() { itimer.cancel(); } 29

30 Example Code int MyConsoleL() { console = Console::NewL(_L("Active Object Sample"), TSize(KConsFullScreen,KConsFullScreen)); CActiveScheduler * as = new (ELeave) CActiveScheduler(); CleanupStack::PushL(as); CActiveScheduler::Install(as); CDelayer * d = CDelayer::NewL(); CleanupStack::PushL(d); d->sethello( ); // Time in in microseconds. CActiveScheduler::Start(); // Delay occurs here. console->printf(_l("ready.\n")); console->getch(); // User intervention CleanupStack::PopAndDestroy(2); // d, as delete console; return 0; } 30

31 Using Active Objects Support included in Symbian Application Framework No need to introduce active scheduler Active objects must still be defined and added to the active scheduler Commonly used in cooperation with Observer design pattern MObserverIF implemented by e.g. AppView component which used in callbacks from AO to GUI Problems Errors: RunError RunL cannot be interrupted; implement longish operations in smaller steps to allow other AOs to execute meanwhile Simple basic scheme, complex implementation framework 31

32 Content and goals Motivation Infrastructure Faking concurrency Mobile Java implementation Symbian OS implementation Threads Active objects Maemo implementation Summary 32

33 Maemo threading and eventing Threading No surprises there Linux threading and processes GTK eventing Mainloop listening for events and reacting accordingly Design mismatch: GTK is not thread-safe Seemingly inexplainable failures when things go wrong Seemingly inexplainable successes at times when context switching occurs in a suitable fashion Design mismatch: Some GTK operations involve threading The programmer must figure out the necessary means to address the problems 33

34 Example: gnome_vfs_async_read void gnome_vfs_async_read ( GnomeVFSAsyncHandle *handle, gpointer buffer, guint bytes, GnomeVFSAsyncReadCallback callback, gpointer callback_data); Read bytes bytes from the file pointed to be handle into buffer. When the operation is complete, callback will be called with the result of the operation and callback_data. ( vfs-20-gnome-vfs-async-ops.html#gnome-vfs-async-read) Looks nice but 34

35 there are complications gnome-vfs async callbacks are called in the main thread, so making GTK+ calls from them is fine. If you are using GTK+ from multiple threads with gdk_threads_init() gdk_threads_enter() gdk_threads_leave() then you have to be aware that the callbacks are called outside the GTK+ lock. But if all your GUI is done in the main thread, then you don't have to worry about it. ( fs%20api+page:1+mid:mlmukdzlpmneuccj+state:results) 35

36 Content and goals Motivation Infrastructure Faking concurrency Mobile Java implementation Symbian OS implementation Threads Active objects Maemo implementation Summary 36

37 Summary Concurrent programming can lead to complex designs regarding critical regions Using program-level pseudo-parallel executions instead of more elaborated implementations can offer benefits Improved portability Smaller memory footprint Simplified programming model and eased debugging Supporting built-in facilities to simplify event handling and threading Java: Green threads; eventing inside GUI framework Symbian: Native threading; eventing with active objects Maemo: Native threading; eventing with GTK events 37

Virtual Machine Design

Virtual Machine Design Virtual Machine Design Lecture 4: Multithreading and Synchronization Antero Taivalsaari September 2003 Session #2026: J2MEPlatform, Connected Limited Device Configuration (CLDC) Lecture Goals Give an overview

More information

Practical Symbian Development

Practical Symbian Development Practical Symbian Development Fabrizio Sannicolò e Marco Cova fabrizio.sannicolo@dit.unitn.it, cova@itc.it Università degli Studi di Trento Facoltà di Scienze MM.FF.NN. Modified by Marco Aiello FOR INTERNAL

More information

POSIX Threads: a first step toward parallel programming. George Bosilca

POSIX Threads: a first step toward parallel programming. George Bosilca POSIX Threads: a first step toward parallel programming George Bosilca bosilca@icl.utk.edu Process vs. Thread A process is a collection of virtual memory space, code, data, and system resources. A thread

More information

Selected topics in Symbian programming

Selected topics in Symbian programming Selected topics in Symbian programming Descriptors, hello-world, dialogs & active objects Søren Debois Department of Theoretical Computer Science IT University of Copenhagen September 23rd, 2005 Søren

More information

Operating Systems (2INC0) 2018/19. Introduction (01) Dr. Tanir Ozcelebi. Courtesy of Prof. Dr. Johan Lukkien. System Architecture and Networking Group

Operating Systems (2INC0) 2018/19. Introduction (01) Dr. Tanir Ozcelebi. Courtesy of Prof. Dr. Johan Lukkien. System Architecture and Networking Group Operating Systems (2INC0) 20/19 Introduction (01) Dr. Courtesy of Prof. Dr. Johan Lukkien System Architecture and Networking Group Course Overview Introduction to operating systems Processes, threads and

More information

Chapter 13 Add Multimedia to Your MIDlets

Chapter 13 Add Multimedia to Your MIDlets Chapter 13 Add Multimedia to Your MIDlets The Mobile Media API (MMAPI), which extends the functions of Java 2 Platform, Micro Edition (J2ME), allows easy and simple access and control of basic audio and

More information

Operating Systems 2010/2011

Operating Systems 2010/2011 Operating Systems 2010/2011 Introduction Johan Lukkien 1 Agenda OS: place in the system Some common notions Motivation & OS tasks Extra-functional requirements Course overview Read chapters 1 + 2 2 A computer

More information

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle Operating Systems Operating System Structure Lecture 2 Michael O Boyle 1 Overview Architecture impact User operating interaction User vs kernel Syscall Operating System structure Layers Examples 2 Lower-level

More information

Java Threads. COMP 585 Noteset #2 1

Java Threads. COMP 585 Noteset #2 1 Java Threads The topic of threads overlaps the boundary between software development and operation systems. Words like process, task, and thread may mean different things depending on the author and the

More information

SymTorrent and GridTorrent: Developing BitTorrent Clients on the Symbian Platform

SymTorrent and GridTorrent: Developing BitTorrent Clients on the Symbian Platform 7 SymTorrent and GridTorrent: Developing BitTorrent Clients on the Symbian Platform Imre Kelényi Budapest University of Technology and Economics, imre.kelenyi@aut.bme.hu Bertalan Forstner Budapest University

More information

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control Processes & Threads Concurrent Programs Process = Address space + one thread of control Concurrent program = multiple threads of control Multiple single-threaded processes Multi-threaded process 2 1 Concurrent

More information

Who am I? Wireless Online Game Development for Mobile Device. What games can you make after this course? Are you take the right course?

Who am I? Wireless Online Game Development for Mobile Device. What games can you make after this course? Are you take the right course? Who am I? Wireless Online Game Development for Mobile Device Lo Chi Wing, Peter Lesson 1 Email: Peter@Peter-Lo.com I123-1-A@Peter Lo 2007 1 I123-1-A@Peter Lo 2007 2 Are you take the right course? This

More information

DAY 3 J2ME March 2007 Aalborg University, Mobile Device Group Mobile Phone Programming

DAY 3 J2ME March 2007 Aalborg University, Mobile Device Group Mobile Phone Programming DAY 3 J2ME Mobile Phone Programming Module 2 Micro (J2ME) Overview Introduction J2ME architecture Introduction 1 J2ME Key Factors Portability: Write once run anywhere Security: Code runs within the confines

More information

CMSC 132: Object-Oriented Programming II. Threads in Java

CMSC 132: Object-Oriented Programming II. Threads in Java CMSC 132: Object-Oriented Programming II Threads in Java 1 Problem Multiple tasks for computer Draw & display images on screen Check keyboard & mouse input Send & receive data on network Read & write files

More information

Memory Management.

Memory Management. Memory Management juha.jarvensivu@tut.fi Content and goals Basics of memory usage in mobile devices Static and dynamic allocation Managing memory organization Memory management in Mobile Java Memory management

More information

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture Last 2 Classes: Introduction to Operating Systems & C++ tutorial User apps OS Virtual machine interface hardware physical machine interface An operating system is the interface between the user and the

More information

CS434/534: Topics in Networked (Networking) Systems

CS434/534: Topics in Networked (Networking) Systems CS434/534: Topics in Networked (Networking) Systems WSN/Mobile Systems Yang (Richard) Yang Computer Science Department Yale University 208A Watson Email: yry@cs.yale.edu http://zoo.cs.yale.edu/classes/cs434/

More information

Concurrent Programming

Concurrent Programming Concurrent Programming is Hard! Concurrent Programming Kai Shen The human mind tends to be sequential Thinking about all possible sequences of events in a computer system is at least error prone and frequently

More information

Concurrent Programming

Concurrent Programming Concurrency Concurrent Programming A sequential program has a single thread of control. Its execution is called a process. A concurrent program has multiple threads of control. They may be executed as

More information

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio Fall 2017 1 Outline Inter-Process Communication (20) Threads

More information

CS5460: Operating Systems

CS5460: Operating Systems CS5460: Operating Systems Lecture 5: Processes and Threads (Chapters 3-4) Context Switch Results lab2-15 gamow home 3.8 us 1.6 us 1.0 us VirtualBox on lab2-25 VirtualBox on gamow VirtualBox on home 170

More information

INF 212 ANALYSIS OF PROG. LANGS CONCURRENCY. Instructors: Crista Lopes Copyright Instructors.

INF 212 ANALYSIS OF PROG. LANGS CONCURRENCY. Instructors: Crista Lopes Copyright Instructors. INF 212 ANALYSIS OF PROG. LANGS CONCURRENCY Instructors: Crista Lopes Copyright Instructors. Basics Concurrent Programming More than one thing at a time Examples: Network server handling hundreds of clients

More information

Dynamically Linked Libraries DLL. Juha JärvensivuJ

Dynamically Linked Libraries DLL. Juha JärvensivuJ Dynamically Linked Libraries DLL Juha JärvensivuJ Content and goals Overview Implementation techniques Plugins Managing memory consumption Using DLLs Mobile Java implementation Symbian OS implementation

More information

Accessing DB2 Everyplace using J2ME devices, part 1

Accessing DB2 Everyplace using J2ME devices, part 1 Accessing DB2 Everyplace using J2ME devices, part 1 Skill Level: Intermediate Naveen Balani (naveenbalani@rediffmail.com) Developer 08 Apr 2004 This two-part tutorial assists developers in developing DB2

More information

Process Characteristics. Threads Chapter 4. Process Characteristics. Multithreading vs. Single threading

Process Characteristics. Threads Chapter 4. Process Characteristics. Multithreading vs. Single threading Process Characteristics Threads Chapter 4 Reading: 4.1,4.4, 4.5 Unit of resource ownership - process is allocated: a virtual address space to hold the process image control of some resources (files, I/O

More information

Threads Chapter 4. Reading: 4.1,4.4, 4.5

Threads Chapter 4. Reading: 4.1,4.4, 4.5 Threads Chapter 4 Reading: 4.1,4.4, 4.5 1 Process Characteristics Unit of resource ownership - process is allocated: a virtual address space to hold the process image control of some resources (files,

More information

User Space Multithreading. Computer Science, University of Warwick

User Space Multithreading. Computer Science, University of Warwick User Space Multithreading 1 Threads Thread short for thread of execution/control B efore create Global During create Global Data Data Executing Code Code Stack Stack Stack A fter create Global Data Executing

More information

Threads SPL/2010 SPL/20 1

Threads SPL/2010 SPL/20 1 Threads 1 Today Processes and Scheduling Threads Abstract Object Models Computation Models Java Support for Threads 2 Process vs. Program processes as the basic unit of execution managed by OS OS as any

More information

CS 160: Interactive Programming

CS 160: Interactive Programming CS 160: Interactive Programming Professor John Canny 3/8/2006 1 Outline Callbacks and Delegates Multi-threaded programming Model-view controller 3/8/2006 2 Callbacks Your code Myclass data method1 method2

More information

Programming in Parallel COMP755

Programming in Parallel COMP755 Programming in Parallel COMP755 All games have morals; and the game of Snakes and Ladders captures, as no other activity can hope to do, the eternal truth that for every ladder you hope to climb, a snake

More information

Dealing with Issues for Interprocess Communication

Dealing with Issues for Interprocess Communication Dealing with Issues for Interprocess Communication Ref Section 2.3 Tanenbaum 7.1 Overview Processes frequently need to communicate with other processes. In a shell pipe the o/p of one process is passed

More information

Unix System Programming - Chapter 2, part a

Unix System Programming - Chapter 2, part a Unix System Programming - Chapter 2, part a Neal Nelson The Evergreen State College Mar 23, 2010 USP Chapter 2.1 to 2.6 Processes and Threads Program Storage and Linkage Library Function Calls Error Handling

More information

2. Memory Management

2. Memory Management 2. Memory Management Basics of memory usage in mobile devices Static and dynamic allocation Managing memory organization Memory management in Symbian OS Memory management in Mobile Java Summary 1 Rationale

More information

4. Dynamic Linking. Summary. DLL structure ECOM

4. Dynamic Linking. Summary. DLL structure ECOM 4. Dynamic Linking Overview Implementation techniques Plugins Managing memory consumption Using DLLs Mobile Java implementation Symbian OS implementation DLL structure ECOM Summary 1 Motivation Several

More information

High Performance Computing Course Notes Shared Memory Parallel Programming

High Performance Computing Course Notes Shared Memory Parallel Programming High Performance Computing Course Notes 2009-2010 2010 Shared Memory Parallel Programming Techniques Multiprocessing User space multithreading Operating system-supported (or kernel) multithreading Distributed

More information

Universal Communication Component on Symbian Series60 Platform

Universal Communication Component on Symbian Series60 Platform Universal Communication Component on Symbian Series60 Platform Róbert Kereskényi, Bertalan Forstner, Hassan Charaf Department of Automation and Applied Informatics Budapest University of Technology and

More information

J2ME With Database Connection Program

J2ME With Database Connection Program J2ME With Database Connection Program Midlet Code: /* * To change this template, choose Tools Templates * and open the template in the editor. package hello; import java.io.*; import java.util.*; import

More information

Mobile Phone Programming

Mobile Phone Programming Mobile Phone Programming Free Study Activity Fall 2006 Day 4 Symbian OS Agenda» Summary of yesterday» Today Symbian Basics cont. DAY4 - Symbian 2 Descriptors Client/server Framework (overview) Active Object

More information

Multithreading and Interactive Programs

Multithreading and Interactive Programs Multithreading and Interactive Programs CS160: User Interfaces John Canny. This time Multithreading for interactivity need and risks Some design patterns for multithreaded programs Debugging multithreaded

More information

CISC2200 Threads Spring 2015

CISC2200 Threads Spring 2015 CISC2200 Threads Spring 2015 Process We learn the concept of process A program in execution A process owns some resources A process executes a program => execution state, PC, We learn that bash creates

More information

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University CS 571 Operating Systems Midterm Review Angelos Stavrou, George Mason University Class Midterm: Grading 2 Grading Midterm: 25% Theory Part 60% (1h 30m) Programming Part 40% (1h) Theory Part (Closed Books):

More information

Exam TI2720-C/TI2725-C Embedded Software

Exam TI2720-C/TI2725-C Embedded Software Exam TI2720-C/TI2725-C Embedded Software Wednesday April 16 2014 (18.30-21.30) Koen Langendoen In order to avoid misunderstanding on the syntactical correctness of code fragments in this examination, we

More information

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies Chapter 2 Processes and Threads Processes The Process Model 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling Multiprogramming of four programs Conceptual

More information

DAY 3 J2ME Aalborg University, Mobile Device Group. Mobile. Mobile Phone Programming

DAY 3 J2ME Aalborg University, Mobile Device Group. Mobile. Mobile Phone Programming DAY 3 J2ME Mobile Phone Programming Java 2 Micro Edition (J2ME) Overview Introduction J2ME architecture MIDlets Application development Introduction J2ME Key Factors Portability: Write once run anywhere

More information

Java Threads. Written by John Bell for CS 342, Spring 2018

Java Threads. Written by John Bell for CS 342, Spring 2018 Java Threads Written by John Bell for CS 342, Spring 2018 Based on chapter 9 of Learning Java, Fourth Edition by Niemeyer and Leuck, and other sources. Processes A process is an instance of a running program.

More information

Synchronization I. Jo, Heeseung

Synchronization I. Jo, Heeseung Synchronization I Jo, Heeseung Today's Topics Synchronization problem Locks 2 Synchronization Threads cooperate in multithreaded programs To share resources, access shared data structures Also, to coordinate

More information

Mobile Devices in Software Engineering. Lab 2

Mobile Devices in Software Engineering. Lab 2 Mobile Devices in Software Engineering Lab 2 Objective The objective of this lab is to: 1. Get you started with network based mobile applications 2. Get you started with persistent storage on mobile devices

More information

Review: Easy Piece 1

Review: Easy Piece 1 CS 537 Lecture 10 Threads Michael Swift 10/9/17 2004-2007 Ed Lazowska, Hank Levy, Andrea and Remzi Arpaci-Dussea, Michael Swift 1 Review: Easy Piece 1 Virtualization CPU Memory Context Switch Schedulers

More information

Java Concurrency in practice Chapter 9 GUI Applications

Java Concurrency in practice Chapter 9 GUI Applications Java Concurrency in practice Chapter 9 GUI Applications INF329 Spring 2007 Presented by Stian and Eirik 1 Chapter 9 GUI Applications GUI applications have their own peculiar threading issues To maintain

More information

Concurrent Programming

Concurrent Programming Concurrent Programming is Hard! Concurrent Programming Kai Shen The human mind tends to be sequential Thinking about all possible sequences of events in a computer system is at least error prone and frequently

More information

Chapter 3 Process Description and Control

Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles Chapter 3 Process Description and Control Seventh Edition By William Stallings Process Control Block Structure of Process Images in Virtual Memory How

More information

Definition Multithreading Models Threading Issues Pthreads (Unix)

Definition Multithreading Models Threading Issues Pthreads (Unix) Chapter 4: Threads Definition Multithreading Models Threading Issues Pthreads (Unix) Solaris 2 Threads Windows 2000 Threads Linux Threads Java Threads 1 Thread A Unix process (heavy-weight process HWP)

More information

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules Brief Preview of Scheduling Concurrency Control Nan Niu (nn@cs.toronto.edu) CSC309 -- Summer 2008 Multiple threads ready to run Some mechanism for switching between them Context switches Some policy for

More information

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst Operating Systems CMPSCI 377 Spring 2017 Mark Corner University of Massachusetts Amherst Last Class: Intro to OS An operating system is the interface between the user and the architecture. User-level Applications

More information

Concurrency in Java Prof. Stephen A. Edwards

Concurrency in Java Prof. Stephen A. Edwards Concurrency in Java Prof. Stephen A. Edwards The Java Language Developed by James Gosling et al. at Sun Microsystems in the early 1990s Originally called Oak, first intended application was as an OS for

More information

Threads. Threads (continued)

Threads. Threads (continued) Threads A thread is an alternative model of program execution A process creates a thread through a system call Thread operates within process context Use of threads effectively splits the process state

More information

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources Concurrency: Deadlock and Starvation Chapter 6 Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other No efficient solution Involve conflicting

More information

Embedded Systems. 5. Operating Systems. Lothar Thiele. Computer Engineering and Networks Laboratory

Embedded Systems. 5. Operating Systems. Lothar Thiele. Computer Engineering and Networks Laboratory Embedded Systems 5. Operating Systems Lothar Thiele Computer Engineering and Networks Laboratory Embedded Operating Systems 5 2 Embedded Operating System (OS) Why an operating system (OS) at all? Same

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Multithreading Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to large compute clusters Can perform multiple

More information

Chapter 4: Multithreaded Programming

Chapter 4: Multithreaded Programming Chapter 4: Multithreaded Programming Silberschatz, Galvin and Gagne 2013 Chapter 4: Multithreaded Programming Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading

More information

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions CMSC 330: Organization of Programming Languages Multithreaded Programming Patterns in Java CMSC 330 2 Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to

More information

Multithreading and Interactive Programs

Multithreading and Interactive Programs Multithreading and Interactive Programs CS160: User Interfaces John Canny. Last time Model-View-Controller Break up a component into Model of the data supporting the App View determining the look of the

More information

Reintroduction to Concurrency

Reintroduction to Concurrency Reintroduction to Concurrency The execution of a concurrent program consists of multiple processes active at the same time. 9/25/14 7 Dining philosophers problem Each philosopher spends some time thinking

More information

Overview. Thread Packages. Threads The Thread Model (1) The Thread Model (2) The Thread Model (3) Thread Usage (1)

Overview. Thread Packages. Threads The Thread Model (1) The Thread Model (2) The Thread Model (3) Thread Usage (1) Overview Thread Packages Thomas Plagemann With slides from O. Anshus, C. Griwodz, M. van Steen, and A. Tanenbaum What are threads? Why threads? Example: Da CaPo 1.0 Thread implementation User level level

More information

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011 Synchronization CS61, Lecture 18 Prof. Stephen Chong November 3, 2011 Announcements Assignment 5 Tell us your group by Sunday Nov 6 Due Thursday Nov 17 Talks of interest in next two days Towards Predictable,

More information

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering) A. Multiple Choice Questions (60 questions) Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering) Unit-I 1. What is operating system? a) collection of programs that manages hardware

More information

I/O Systems. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

I/O Systems. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic) I/O Systems Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic) Amir H. Payberah (Tehran Polytechnic) I/O Systems 1393/9/15 1 / 57 Motivation Amir H. Payberah (Tehran

More information

Lecture 7 Java SE Multithreading

Lecture 7 Java SE Multithreading Lecture 7 Java SE Multithreading presentation Java Programming Software App Development Cristian Toma D.I.C.E/D.E.I.C Department of Economic Informatics & Cybernetics www.dice.ase.ro Cristian Toma Business

More information

Chapter 4: Multithreaded

Chapter 4: Multithreaded Chapter 4: Multithreaded Programming Chapter 4: Multithreaded Programming Overview Multithreading Models Thread Libraries Threading Issues Operating-System Examples 2009/10/19 2 4.1 Overview A thread is

More information

Parallelism Marco Serafini

Parallelism Marco Serafini Parallelism Marco Serafini COMPSCI 590S Lecture 3 Announcements Reviews First paper posted on website Review due by this Wednesday 11 PM (hard deadline) Data Science Career Mixer (save the date!) November

More information

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation Chapter 2 Processes The Process Model Processes and Threads 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling Multiprogramming of four programs Conceptual

More information

Overview of Java Threads (Part 2)

Overview of Java Threads (Part 2) Overview of Java Threads (Part 2) Douglas C. Schmidt d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/~schmidt Institute for Software Integrated Systems Vanderbilt University Nashville, Tennessee, USA Learning

More information

Threading and Synchronization. Fahd Albinali

Threading and Synchronization. Fahd Albinali Threading and Synchronization Fahd Albinali Parallelism Parallelism and Pseudoparallelism Why parallelize? Finding parallelism Advantages: better load balancing, better scalability Disadvantages: process/thread

More information

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Chapter 4: Threads Silberschatz, Galvin and Gagne 2013 Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues 4.2 Silberschatz, Galvin

More information

MCS-378 Intraterm Exam 1 Serial #:

MCS-378 Intraterm Exam 1 Serial #: MCS-378 Intraterm Exam 1 Serial #: This exam is closed-book and mostly closed-notes. You may, however, use a single 8 1/2 by 11 sheet of paper with hand-written notes for reference. (Both sides of the

More information

Zing Vision. Answering your toughest production Java performance questions

Zing Vision. Answering your toughest production Java performance questions Zing Vision Answering your toughest production Java performance questions Outline What is Zing Vision? Where does Zing Vision fit in your Java environment? Key features How it works Using ZVRobot Q & A

More information

Asynchronous Database Access with Qt 4.x

Asynchronous Database Access with Qt 4.x Asynchronous Database Access with Qt 4.x Dave Berton Abstract How to code around the default synchronous database access in Qt 4. The database support in Qt 4.x is quite robust. The library includes drivers

More information

Real-Time Programming

Real-Time Programming Real-Time Programming Week 7: Real-Time Operating Systems Instructors Tony Montiel & Ken Arnold rtp@hte.com 4/1/2003 Co Montiel 1 Objectives o Introduction to RTOS o Event Driven Systems o Synchronization

More information

Chapter 4: Multithreaded Programming

Chapter 4: Multithreaded Programming Chapter 4: Multithreaded Programming Silberschatz, Galvin and Gagne 2013! Chapter 4: Multithreaded Programming Overview Multicore Programming Multithreading Models Threading Issues Operating System Examples

More information

2. Memory Management. Rationale. Memory. Program and Stack. Example. Activation. Dynamic allocation. devices

2. Memory Management. Rationale. Memory. Program and Stack. Example. Activation. Dynamic allocation. devices 2. Memory Management Rationale Memory usage is a tangling concern in mobile devices All programs use memory In order to reduce costs, only limited amount of memory available in mobile devices Also power

More information

J2ME crash course. Harald Holone

J2ME crash course. Harald Holone J2ME crash course Harald Holone 2006-01-24 Abstract This article gives a short, hands-on introduction to programming J2ME applications on the MIDP 2.0 platform. Basic concepts, such as configurations,

More information

COMP 3430 Robert Guderian

COMP 3430 Robert Guderian Operating Systems COMP 3430 Robert Guderian file:///users/robg/dropbox/teaching/3430-2018/slides/04_threads/index.html?print-pdf#/ 1/58 1 Threads Last week: Processes This week: Lesser processes! file:///users/robg/dropbox/teaching/3430-2018/slides/04_threads/index.html?print-pdf#/

More information

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits CS307 What is a thread? Threads A thread is a basic unit of CPU utilization contains a thread ID, a program counter, a register set, and a stack shares with other threads belonging to the same process

More information

4. Concurrency via Threads

4. Concurrency via Threads CSC400 - Operating Systems 4. Concurrency via Threads J. Sumey Overview Multithreading Concept Background Implementations Thread States & Thread Switching Thread Operations Case Study: pthreads CSC400

More information

Synchronization: Basics

Synchronization: Basics Synchronization: Basics 53: Introduction to Computer Systems 4 th Lecture, April 8, 7 Instructor: Seth Copen Goldstein, Franz Franchetti Today Threads review Sharing Mutual exclusion Semaphores Traditional

More information

OPERATING SYSTEM. Chapter 4: Threads

OPERATING SYSTEM. Chapter 4: Threads OPERATING SYSTEM Chapter 4: Threads Chapter 4: Threads Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues Operating System Examples Objectives To

More information

Chapter 3: Processes. Operating System Concepts 8th Edition

Chapter 3: Processes. Operating System Concepts 8th Edition Chapter 3: Processes Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server Systems 3.2 Objectives

More information

Parallelism and Concurrency. Motivation, Challenges, Impact on Software Development CSE 110 Winter 2016

Parallelism and Concurrency. Motivation, Challenges, Impact on Software Development CSE 110 Winter 2016 Parallelism and Concurrency Motivation, Challenges, Impact on Software Development CSE 110 Winter 2016 About These Slides Due to the nature of this material, this lecture was delivered via the chalkboard.

More information

Agenda. Threads. Single and Multi-threaded Processes. What is Thread. CSCI 444/544 Operating Systems Fall 2008

Agenda. Threads. Single and Multi-threaded Processes. What is Thread. CSCI 444/544 Operating Systems Fall 2008 Agenda Threads CSCI 444/544 Operating Systems Fall 2008 Thread concept Thread vs process Thread implementation - user-level - kernel-level - hybrid Inter-process (inter-thread) communication What is Thread

More information

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable What s An OS? Provides environment for executing programs Process abstraction for multitasking/concurrency scheduling Hardware abstraction layer (device drivers) File systems Communication Do we need an

More information

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5 Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5 Multiple Processes OS design is concerned with the management of processes and threads: Multiprogramming Multiprocessing Distributed processing

More information

Synchronization. Disclaimer: some slides are adopted from the book authors slides with permission 1

Synchronization. Disclaimer: some slides are adopted from the book authors slides with permission 1 Synchronization Disclaimer: some slides are adopted from the book authors slides with permission 1 What is it? Recap: Thread Independent flow of control What does it need (thread private)? Stack What for?

More information

Mobile Devices in Software Engineering. Lab 3

Mobile Devices in Software Engineering. Lab 3 Mobile Devices in Software Engineering Lab 3 Objective The objective of this lab is to: 1. Test various GUI components on your device 2. Continue to develop application on mobile devices Experiment 1 In

More information

Performance Throughput Utilization of system resources

Performance Throughput Utilization of system resources Concurrency 1. Why concurrent programming?... 2 2. Evolution... 2 3. Definitions... 3 4. Concurrent languages... 5 5. Problems with concurrency... 6 6. Process Interactions... 7 7. Low-level Concurrency

More information

Concurrency COMS W4115. Prof. Stephen A. Edwards Spring 2002 Columbia University Department of Computer Science

Concurrency COMS W4115. Prof. Stephen A. Edwards Spring 2002 Columbia University Department of Computer Science Concurrency COMS W4115 Prof. Stephen A. Edwards Spring 2002 Columbia University Department of Computer Science Concurrency Multiple, simultaneous execution contexts. Want to walk and chew gum at the same

More information

THREADS & CONCURRENCY

THREADS & CONCURRENCY 27/04/2018 Sorry for the delay in getting slides for today 2 Another reason for the delay: Yesterday: 63 posts on the course Piazza yesterday. A7: If you received 100 for correctness (perhaps minus a late

More information

Implementing Coroutines. Faking Coroutines in Java

Implementing Coroutines. Faking Coroutines in Java Concurrency Coroutines Concurrency COMS W4115 Prof. Stephen A. Edwards Spring 2002 Columbia University Department of Computer Science Multiple, simultaneous execution contexts. Want to walk and chew gum

More information

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Synchronization I Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics Synchronization problem Locks 2 Synchronization Threads cooperate

More information

Verification of Real-Time Systems Resource Sharing

Verification of Real-Time Systems Resource Sharing Verification of Real-Time Systems Resource Sharing Jan Reineke Advanced Lecture, Summer 2015 Resource Sharing So far, we have assumed sets of independent tasks. However, tasks may share resources to communicate

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 12: Scheduling & Deadlock Priority Scheduling Priority Scheduling Choose next job based on priority» Airline checkin for first class passengers Can

More information