SlideShare a Scribd company logo
1 of 17
Real-time  Embedded Systems- Lecture 03 Real-time Embedded Systems Lecture 3 RT Systems Essentials Part II RTOS-Synchronizatiion Prof. Dr. Amitava Gupta Department of Power Engineering Jadavpur University, Kolkata
Synchronization Techniques in RTOSs Explicit Implicit Cross Stimulation Semaphores Event flags shared Single proc. shared Single proc. flag counting burst fifo Real-time  Embedded Systems- Lecture 03
Explicit Task Synchronization by Cross Stimulation The synchronizing processes know each others task id. Example Consider a system comprising two tasks. One task samples a set of temperature data from field sensors and another task computes the deviations from set values and switches on or off the devices that cause heating/cooling (actuators). timeframe T 1 T 2 Task T 1  collects data and stimulates T 2 Real-time  Embedded Systems- Lecture 03
Advantages This scheme ensures that T 2  always processes the latest temperature data. Also it ensures that the task T 2  does not access the shared resource when T 1  writes on it. Disadvantages Depend on how the cross stimulation is implemented. If it is blocking, i.e. T 2  waits for the stimulation from T 1 , then the scheme has several problems:- T 2  should have a shorter period that T 1 If T 1  gets blocked, T 2  gets blocked too. What happens if the number of scanner tasks is more than one? Real-time  Embedded Systems- Lecture 03
Using semaphores  A semaphore is a structure that is used to guard access to a shared resource. It could be a  flag  or a multi-valued integer ( counting semaphore )   As a  flag , the following operations are possible on a semaphore: set   reset As a  counting semaphore , these are: increment decrement ( a set operation) ( a reset operation) Real-time  Embedded Systems- Lecture 03
The temperature controller using a flag semaphore timeframe T 1 T 2 Task T 1  collects data  Task T 1  sets the semaphore, writes the data  resets the semaphore No access for T 2  now Task T2 sets the semaphore reads the data resets the semaphore No access for T 1  now Real-time  Embedded Systems- Lecture 03
Using semaphores: the  Deadly Embrace  problem  Task T 1  pseudocode While (forever) { set semaphore_A ----------------------- ------------------------ set semaphore_B ----------------------- ----------------------- reset semaphore_A reset semaphore_B } Task T 2  pseudocode While (forever) { set semaphore_B ----------------------- ------------------------ set semaphore_A ----------------------- ----------------------- reset semaphore_B reset semaphore_A } Task T 1  blocks here Task T 2  blocks here Real-time  Embedded Systems- Lecture 03
Moral of the story ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The ultimate bottomline ( on a lighter note, though) is peace and  is war ! Real-time  Embedded Systems- Lecture 03
The problem continues…. Priority inversion Let us suppose, we have 3 tasks,  A ,  B  and  C  which share a semaphore amongst them. The  priority sequence is  A  >  B  >  C .  Let us suppose that  C  runs for some time, having set the semaphore, when it is pre-empted by  A S After having run for sometime,  A  tries to set the same semaphore and is blocked. S Now, if  B  is ready, it will run-displacing  A , a higher priority task. A possible solution would be to increase the priority of  C  to level more than that of  B , till it resets the semaphore. Real-time  Embedded Systems- Lecture 03
The counting semaphore Basic operation Each semaphore is associated with a MAX_COUNT value and is initialized to an initial value which is usually zero. Each  set  or  increment  will increase the COUNT by unity. When the COUNT reaches MAX_COUNT, the task trying to  set  will block. Each  reset  or  decrement  will decrease the COUNT by unity. When the COUNT reaches zero, the task trying to reset will block. This is ideal for a  producer-consumer  environment Real-time  Embedded Systems- Lecture 03
The counting semaphore in a  producer-consumer  environment We assume that the  Scanner  task writes data on to a buffer which is read by the  Controller. Thus the  Scanner  is the producer here and the  Controller  is the consumer. We further assume that the buffer can hold 2 data elements. We use a counting semaphore with a MAX_COUNT value of 2. The execution profile of the producer and the consumer Chalk and board Real-time  Embedded Systems- Lecture 03
The Burst and FIFO mode of operation of semaphores Burst Mode : In this mode, if a number of tasks are in the blocked state waiting to set the semaphore, the task with the highest priority gets unblocked first. FIFO Mode : In this mode, if a number of tasks are in the blocked state waiting to set the semaphore, they get unblocked in the sequence they posted a request for set . Real-time  Embedded Systems- Lecture 03
Execution Profile: Burst and FIFO mode semaphores Burst Mode Task priority  A  >  B   >   C   >  D s s s s r r r D  sets the semaphore & is pre-empted by  B B  is blocked when it tries to set the semaphore C  is blocked when it tries to  set the semaphore A  is blocked when it tries to set the semaphore When  D  resets the semaphore,  A  gets  It even though other tasks had posted  requests before. Real-time  Embedded Systems- Lecture 03
Execution Profile: Burst and FIFO mode semaphores FIFO  Mode Task priority  A  >  B   >  C   >  D s s s s r r r Task  B  gets the semaphore now. Real-time  Embedded Systems- Lecture 03
The Event Flag Basic operation An  Event Flag  is a single byte or a two byte integer which is used to synchronize processes particularly in a producer-consumer environment. A Producer sets one or more bits in a pre- determined manner ……………… .. A consumer is activated when a certain combination is satisfied. This is determined by the application Real-time  Embedded Systems- Lecture 03
The Multi-processor support Semaphores and Event Flags may be used to share resources across processors in a  multi-processor  environment. Such structures are located in the shared global memory . The usage is usually implementation specific with the following basic properties: Sharing is  explicit . A shared synchronization structure has pre-defined processors associated with it. Semaphores (both flag and counting) are almost  always in the FIFO mode . Real-time  Embedded Systems- Lecture 03
The Last Word Initialization of Synchronization structures is Application Programmer's responsibility. An Application has to create and initialize these structures before they are used by any task. The OS provides the necessary system calls. Usually, this is done by a startup task which starts first when the application starts and  then other tasks are started. Goodbye till next week. Please do not forget to bring a Calculator! Real-time  Embedded Systems- Lecture 03

More Related Content

What's hot

Chapter 19 - Real Time Systems
Chapter 19 - Real Time SystemsChapter 19 - Real Time Systems
Chapter 19 - Real Time SystemsWayne Jones Jnr
 
Components in real time systems
Components in real time systemsComponents in real time systems
Components in real time systemsSaransh Garg
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating SystemsRohit Joshi
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating SystemsAshwani Garg
 
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time SystemsSara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systemsknowdiff
 
Real time scheduling - basic concepts
Real time scheduling - basic conceptsReal time scheduling - basic concepts
Real time scheduling - basic conceptsStudent
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating SystemsPawandeep Kaur
 
Real time operating system
Real time operating systemReal time operating system
Real time operating systemKhuram Shahzad
 
Real-Time Scheduling
Real-Time SchedulingReal-Time Scheduling
Real-Time Schedulingsathish sak
 
REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1Embeddedcraft Craft
 
RTOS- Real Time Operating Systems
RTOS- Real Time Operating Systems RTOS- Real Time Operating Systems
RTOS- Real Time Operating Systems Bayar shahab
 
Real time operating-systems
Real time operating-systemsReal time operating-systems
Real time operating-systemskasi963
 
Basic functions & types of RTOS ES
Basic functions & types of  RTOS ESBasic functions & types of  RTOS ES
Basic functions & types of RTOS ESJOLLUSUDARSHANREDDY
 
Real Time Systems & RTOS
Real Time Systems & RTOSReal Time Systems & RTOS
Real Time Systems & RTOSVishwa Mohan
 
Lecture 3
Lecture 3Lecture 3
Lecture 3Mr SMAK
 

What's hot (20)

Chapter 19 - Real Time Systems
Chapter 19 - Real Time SystemsChapter 19 - Real Time Systems
Chapter 19 - Real Time Systems
 
Real time-embedded-system-lec-07
Real time-embedded-system-lec-07Real time-embedded-system-lec-07
Real time-embedded-system-lec-07
 
Components in real time systems
Components in real time systemsComponents in real time systems
Components in real time systems
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time SystemsSara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
 
Real time scheduling - basic concepts
Real time scheduling - basic conceptsReal time scheduling - basic concepts
Real time scheduling - basic concepts
 
Real Time System
Real Time SystemReal Time System
Real Time System
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Real time operating system
Real time operating systemReal time operating system
Real time operating system
 
Real-Time Scheduling
Real-Time SchedulingReal-Time Scheduling
Real-Time Scheduling
 
1.prallelism
1.prallelism1.prallelism
1.prallelism
 
REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1
 
Real-Time Operating Systems
Real-Time Operating SystemsReal-Time Operating Systems
Real-Time Operating Systems
 
RTOS- Real Time Operating Systems
RTOS- Real Time Operating Systems RTOS- Real Time Operating Systems
RTOS- Real Time Operating Systems
 
Real time operating-systems
Real time operating-systemsReal time operating-systems
Real time operating-systems
 
Basic functions & types of RTOS ES
Basic functions & types of  RTOS ESBasic functions & types of  RTOS ES
Basic functions & types of RTOS ES
 
Real Time Systems & RTOS
Real Time Systems & RTOSReal Time Systems & RTOS
Real Time Systems & RTOS
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
RTOS
RTOSRTOS
RTOS
 

Similar to Real time-embedded-system-lec-03

PART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with DebuggingPART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with DebuggingFastBit Embedded Brain Academy
 
Os files 2
Os files 2Os files 2
Os files 2Amit Pal
 
RTOS implementation
RTOS implementationRTOS implementation
RTOS implementationRajan Kumar
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OSC.U
 
seminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdfseminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdfkarunyamittapally
 
Processes, Threads and Scheduler
Processes, Threads and SchedulerProcesses, Threads and Scheduler
Processes, Threads and SchedulerMunazza-Mah-Jabeen
 
Bt0070, operating systems
Bt0070, operating systemsBt0070, operating systems
Bt0070, operating systemssmumbahelp
 
Bca2010 – operating system
Bca2010 – operating systemBca2010 – operating system
Bca2010 – operating systemsmumbahelp
 
Bca2010 – operating system
Bca2010 – operating systemBca2010 – operating system
Bca2010 – operating systemsmumbahelp
 
Monitor(karthika)
Monitor(karthika)Monitor(karthika)
Monitor(karthika)Nagarajan
 
Lecture18-19 (1).ppt
Lecture18-19 (1).pptLecture18-19 (1).ppt
Lecture18-19 (1).pptssuserf67e3a
 
VCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxVCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxskilljiolms
 
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Sivaranjan Goswami
 

Similar to Real time-embedded-system-lec-03 (20)

PART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with DebuggingPART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
 
Os files 2
Os files 2Os files 2
Os files 2
 
RTOS implementation
RTOS implementationRTOS implementation
RTOS implementation
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OS
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
seminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdfseminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdf
 
Processes, Threads and Scheduler
Processes, Threads and SchedulerProcesses, Threads and Scheduler
Processes, Threads and Scheduler
 
Bt0070, operating systems
Bt0070, operating systemsBt0070, operating systems
Bt0070, operating systems
 
Bca2010 – operating system
Bca2010 – operating systemBca2010 – operating system
Bca2010 – operating system
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systems
 
rtos by mohit
rtos by mohitrtos by mohit
rtos by mohit
 
Real time-embedded-system-lec-02
Real time-embedded-system-lec-02Real time-embedded-system-lec-02
Real time-embedded-system-lec-02
 
Bca2010 – operating system
Bca2010 – operating systemBca2010 – operating system
Bca2010 – operating system
 
Monitor(karthika)
Monitor(karthika)Monitor(karthika)
Monitor(karthika)
 
ES-CH5.ppt
ES-CH5.pptES-CH5.ppt
ES-CH5.ppt
 
Lecture18-19 (1).ppt
Lecture18-19 (1).pptLecture18-19 (1).ppt
Lecture18-19 (1).ppt
 
VCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxVCE Unit 01 (1).pptx
VCE Unit 01 (1).pptx
 
Matopt
MatoptMatopt
Matopt
 
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
 

More from University of Computer Science and Technology (14)

12 software maintenance
12 software maintenance12 software maintenance
12 software maintenance
 
11 software testing_strategy
11 software testing_strategy11 software testing_strategy
11 software testing_strategy
 
10 software testing_technique
10 software testing_technique10 software testing_technique
10 software testing_technique
 
09 coding standards_n_guidelines
09 coding standards_n_guidelines09 coding standards_n_guidelines
09 coding standards_n_guidelines
 
08 component level_design
08 component level_design08 component level_design
08 component level_design
 
07 interface design
07 interface design07 interface design
07 interface design
 
06 architectural design_workout
06 architectural design_workout06 architectural design_workout
06 architectural design_workout
 
05 architectural design
05 architectural design05 architectural design
05 architectural design
 
04 design concepts_n_principles
04 design concepts_n_principles04 design concepts_n_principles
04 design concepts_n_principles
 
03 requirement engineering_process
03 requirement engineering_process03 requirement engineering_process
03 requirement engineering_process
 
02 software process_models
02 software process_models02 software process_models
02 software process_models
 
01 software engineering_aspects
01 software engineering_aspects01 software engineering_aspects
01 software engineering_aspects
 
14 software technical_metrics
14 software technical_metrics14 software technical_metrics
14 software technical_metrics
 
13 software metrics
13 software metrics13 software metrics
13 software metrics
 

Recently uploaded

Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 

Recently uploaded (20)

Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 

Real time-embedded-system-lec-03

  • 1. Real-time Embedded Systems- Lecture 03 Real-time Embedded Systems Lecture 3 RT Systems Essentials Part II RTOS-Synchronizatiion Prof. Dr. Amitava Gupta Department of Power Engineering Jadavpur University, Kolkata
  • 2. Synchronization Techniques in RTOSs Explicit Implicit Cross Stimulation Semaphores Event flags shared Single proc. shared Single proc. flag counting burst fifo Real-time Embedded Systems- Lecture 03
  • 3. Explicit Task Synchronization by Cross Stimulation The synchronizing processes know each others task id. Example Consider a system comprising two tasks. One task samples a set of temperature data from field sensors and another task computes the deviations from set values and switches on or off the devices that cause heating/cooling (actuators). timeframe T 1 T 2 Task T 1 collects data and stimulates T 2 Real-time Embedded Systems- Lecture 03
  • 4. Advantages This scheme ensures that T 2 always processes the latest temperature data. Also it ensures that the task T 2 does not access the shared resource when T 1 writes on it. Disadvantages Depend on how the cross stimulation is implemented. If it is blocking, i.e. T 2 waits for the stimulation from T 1 , then the scheme has several problems:- T 2 should have a shorter period that T 1 If T 1 gets blocked, T 2 gets blocked too. What happens if the number of scanner tasks is more than one? Real-time Embedded Systems- Lecture 03
  • 5. Using semaphores A semaphore is a structure that is used to guard access to a shared resource. It could be a flag or a multi-valued integer ( counting semaphore ) As a flag , the following operations are possible on a semaphore: set reset As a counting semaphore , these are: increment decrement ( a set operation) ( a reset operation) Real-time Embedded Systems- Lecture 03
  • 6. The temperature controller using a flag semaphore timeframe T 1 T 2 Task T 1 collects data Task T 1 sets the semaphore, writes the data resets the semaphore No access for T 2 now Task T2 sets the semaphore reads the data resets the semaphore No access for T 1 now Real-time Embedded Systems- Lecture 03
  • 7. Using semaphores: the Deadly Embrace problem Task T 1 pseudocode While (forever) { set semaphore_A ----------------------- ------------------------ set semaphore_B ----------------------- ----------------------- reset semaphore_A reset semaphore_B } Task T 2 pseudocode While (forever) { set semaphore_B ----------------------- ------------------------ set semaphore_A ----------------------- ----------------------- reset semaphore_B reset semaphore_A } Task T 1 blocks here Task T 2 blocks here Real-time Embedded Systems- Lecture 03
  • 8.
  • 9. The problem continues…. Priority inversion Let us suppose, we have 3 tasks, A , B and C which share a semaphore amongst them. The priority sequence is A > B > C . Let us suppose that C runs for some time, having set the semaphore, when it is pre-empted by A S After having run for sometime, A tries to set the same semaphore and is blocked. S Now, if B is ready, it will run-displacing A , a higher priority task. A possible solution would be to increase the priority of C to level more than that of B , till it resets the semaphore. Real-time Embedded Systems- Lecture 03
  • 10. The counting semaphore Basic operation Each semaphore is associated with a MAX_COUNT value and is initialized to an initial value which is usually zero. Each set or increment will increase the COUNT by unity. When the COUNT reaches MAX_COUNT, the task trying to set will block. Each reset or decrement will decrease the COUNT by unity. When the COUNT reaches zero, the task trying to reset will block. This is ideal for a producer-consumer environment Real-time Embedded Systems- Lecture 03
  • 11. The counting semaphore in a producer-consumer environment We assume that the Scanner task writes data on to a buffer which is read by the Controller. Thus the Scanner is the producer here and the Controller is the consumer. We further assume that the buffer can hold 2 data elements. We use a counting semaphore with a MAX_COUNT value of 2. The execution profile of the producer and the consumer Chalk and board Real-time Embedded Systems- Lecture 03
  • 12. The Burst and FIFO mode of operation of semaphores Burst Mode : In this mode, if a number of tasks are in the blocked state waiting to set the semaphore, the task with the highest priority gets unblocked first. FIFO Mode : In this mode, if a number of tasks are in the blocked state waiting to set the semaphore, they get unblocked in the sequence they posted a request for set . Real-time Embedded Systems- Lecture 03
  • 13. Execution Profile: Burst and FIFO mode semaphores Burst Mode Task priority A > B > C > D s s s s r r r D sets the semaphore & is pre-empted by B B is blocked when it tries to set the semaphore C is blocked when it tries to set the semaphore A is blocked when it tries to set the semaphore When D resets the semaphore, A gets It even though other tasks had posted requests before. Real-time Embedded Systems- Lecture 03
  • 14. Execution Profile: Burst and FIFO mode semaphores FIFO Mode Task priority A > B > C > D s s s s r r r Task B gets the semaphore now. Real-time Embedded Systems- Lecture 03
  • 15. The Event Flag Basic operation An Event Flag is a single byte or a two byte integer which is used to synchronize processes particularly in a producer-consumer environment. A Producer sets one or more bits in a pre- determined manner ……………… .. A consumer is activated when a certain combination is satisfied. This is determined by the application Real-time Embedded Systems- Lecture 03
  • 16. The Multi-processor support Semaphores and Event Flags may be used to share resources across processors in a multi-processor environment. Such structures are located in the shared global memory . The usage is usually implementation specific with the following basic properties: Sharing is explicit . A shared synchronization structure has pre-defined processors associated with it. Semaphores (both flag and counting) are almost always in the FIFO mode . Real-time Embedded Systems- Lecture 03
  • 17. The Last Word Initialization of Synchronization structures is Application Programmer's responsibility. An Application has to create and initialize these structures before they are used by any task. The OS provides the necessary system calls. Usually, this is done by a startup task which starts first when the application starts and then other tasks are started. Goodbye till next week. Please do not forget to bring a Calculator! Real-time Embedded Systems- Lecture 03