Laboratory - 4.  Threading Concept  Threading in.NET  Multi-Threaded Socket  Example.

Slides:



Advertisements
Similar presentations
Chapter 15 Multithreading, Networks, and Client/Server Programming
Advertisements

CHAPTER 5 THREADS & MULTITHREADING 1. Single and Multithreaded Processes 2.
Using TCP sockets in Java Created by M Bateman, A Ruddle & C Allison As part of the TCP View project.
Chapter 5 Threads os5.
Threads Load new page Page is loading Browser still responds to user (can read pages in other tabs)
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Server Architecture Models Operating Systems Hebrew University Spring 2004.
Multithreaded Java COMP1681 / SE15 Introduction to Programming Fast Track Session 3.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Application Layer PART VI.
Cosc 4755 Phone programming: GUI Concepts & Threads.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Fundamentals of Python: From First Programs Through Data Structures
Chapter 26 Client Server Interaction Communication across a computer network requires a pair of application programs to cooperate. One application on one.
Multithreading.
Threading in Java – a Tutorial QMUL IEEE SB. Why Threading When we need to run two tasks concurrently So multiple parts (>=2) of a program can run simultaneously.
Computer Architecture Parallel Processing
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
Today’s topic Other server design alternatives –Preforked servers –Threaded servers –Prethreaded servers.
Introduction to Threads CS240 Programming in C. Introduction to Threads A thread is a path execution By default, a C/C++ program has one thread called.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
Chapter 2 (PART 1) Light-Weight Process (Threads) Department of Computer Science Southern Illinois University Edwardsville Summer, 2004 Dr. Hiroshi Fujinoki.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Concurrent Programming. Concurrency  Concurrency means for a program to have multiple paths of execution running at (almost) the same time. Examples:
C# I 1 CSC 298 Threads. C# I 2 Introducing Threads  A thread is a flow of control within a program  A piece of code that runs on its own. The execution.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
A Brief Documentation.  Provides basic information about connection, server, and client.
1.NETConcurrent programmingNOEA / PQC 2007 Concurrent programming Threads –Introduction –Synchronization.
CS333 Intro to Operating Systems Jonathan Walpole.
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
Threads & Networking C# offers facilities for multi threading and network programming an application roughly corresponds to a process, handled by the OS.
Position of application layer. Application layer duties.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Using Threads SWE 344 Internet Protocols & Client Server Programming.
Threads Doing Several Things at Once. Threads n What are Threads? n Two Ways to Obtain a New Thread n The Lifecycle of a Thread n Four Kinds of Thread.
1 Client-Server Interaction. 2 Functionality Transport layer and layers below –Basic communication –Reliability Application layer –Abstractions Files.
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
1 CSCD 330 Network Programming Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 9 Client-Server Programming.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Parallel Processing (CS526) Spring 2012(Week 8).  Shared Memory Architecture  Shared Memory Programming & PLs  Java Threads  Preparing the Environment.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Threads. Readings r Silberschatz et al : Chapter 4.
Distributed Systems CS Project 1: File Storage and Access Kit (FileStack) Recitation 1, Aug 29, 2013 Dania Abed Rabbou and Mohammad Hammoud.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
CSC 480 Software Engineering Lab 2 – Multi-Threading Oct 18, 2002.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 K. Salah Application Layer Module K. Salah Network layer duties.
Threads by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
Lecture 6 Threads Erick Pranata
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Threaded Programming in Python
Multi Threading.
PA1 Discussion.
Threads and Scheduling
Implementation CAN Communication Engine
Distributed Systems - Comp 655
Chapter 4 Multithreading programming
CNT 4007C Project 2 Good morning, everyone. In this class, we will have a brief look at the project 2. Project 2 is basically the same with project 1.
Processes and Threads.
Multithreaded Programming
Threaded Programming in Python
Operating Systems (CS 340 D)
- When you approach operating system concepts there might be several confusing terms that may look similar but in fact refer to different concepts:  multiprogramming, multiprocessing, multitasking,
Multithreading in java.
NETWORK PROGRAMMING CNET 441
MULTITHREADING PROGRAMMING
CMSC 202 Threads.
Ch 3.
Presentation transcript:

Laboratory - 4

 Threading Concept  Threading in.NET  Multi-Threaded Socket  Example

 A thread is like a replication of a process but each replication is still belonging to a same process.  Operating system concept ◦ Thread – lightweight process ◦ Process – program in memory ◦ Program – set of instruction  Thread share memory but process has its own memory

 Example : SimpleThread.cs  Thread class  4 constructors public Thread(ThreadStart) public Thread(ParameterizedThreadStart) public Thread(ThreadStart, int) public Thread(ParameterizedThreadStart, int)  Requires ThreadStart delegate for thread with no parameter  Thread with parameter will require ParameterizedThreadStart

 ThreadStart class SomeClass { void SomeThreadMethod() { // Some task to be performed here } void NormalMethod() { ThreadStart ts = new ThreadStart(SomeThreadMethod); Thread t = new Thread(ts); t.Start(); }

 It seems that each thread runs concurrently  But in practice, the context switching between threads are so fast, it appears parallelism  The execution order of each thread is random  In some cases, we need to have a certain task within a thread to be completed first before a context switching is carried out.  For example: Race condition (RaceCondition.cs)

 Many methods are available to initiate thread synchronization.  In this class we will use three synchronization technique: ◦ Lock ◦ Monitor ◦ Mutex  Example (Source code are given)

 Previously, server can handle only one client per time  We need to have a way to handle multiple client connection

 In connection-oriented protocol, the RemoteEndPoint property gets the EndPoint containing the remote IP address and port number to which the Socket is connected.  The RemoteEndPoint is set after a call to either Accept or Connect.  It is not needed to put the whole socket program within the threading method.  The part of the socket program requires to run concurrently will only be in included in multithreading method.

 Multi-Threaded Server

 Listener Flow

 Example: EchoServerMT.cs