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

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Recently uploaded (20)

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

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