intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Bài giảng Real-time Systems Week 3: Task and Task Synchronization

Chia sẻ: Codon_06 Codon_06 | Ngày: | Loại File: PDF | Số trang:31

42
lượt xem
1
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Bài giảng Real-time Systems Week 3: Task and Task Synchronization tập trung trình bày các vấn đề về Task; Task synchronization; Deadlock;... Hy vọng tài liệu là nguồn thông tin hữu ích cho quá trình học tập và nghiên cứu của các bạn.

Chủ đề:
Lưu

Nội dung Text: Bài giảng Real-time Systems Week 3: Task and Task Synchronization

  1. Real-time Systems Week 3: Task and Task Synchronization Ngo Lam Trung Dept. of Computer Engineering NLT, SoICT, 2015
  2. Content  Task  Task synchronization  Semaphore and mutex  Philosopher’s problem  Deadlock NLT, SoICT, 2015
  3. Defining a task  Independent thread of execution that can compete with concurrent tasks for processor execution time.  Thus, schedulable & allocated a priority level according to the scheduling algorithm  Elements of a task  Unique ID  Task control block (TCB)  Stack  Priority (if part of a preemptive scheduling plan)  Task routine NLT, SoICT, 2015
  4. Elements of a task NLT, SoICT, 2015
  5. Task states & scheduling  Task states:  Ready state  Running state  Blocked state  Scheduler determines each running blocked task’s state. dispatched preempted unblocked ready blocked unblocked NLT, SoICT, 2015
  6. Task states  ready state-the task is ready to run but cannot because a higher priority task is executing.  blocked state-the task has requested a resource that is not available, has requested to wait until some event occurs, or has delayed itself for some duration.  running state-the task is the highest priority task and is running. NLT, SoICT, 2015
  7. Typical task structure(1)  Typical task structures:  Run-to-completion task: Useful for initialization & startup tasks NLT, SoICT, 2015
  8. Typical task structure(2)  Typical task structures:  Endless-loop task: Work in an application by handling inputs & outputs NLT, SoICT, 2015
  9. Semaphores  In multi-task systems, concurrently-running tasks should be able to  synchronize their execution, and  to coordinate mutual exclusive access to shared resources.  What is semaphore?  A kernel object to realize synchronization & mutual exclusion  One or more threads of execution can acquire & release to execute an operation to be synchronized or to access to a shared resource. NLT, SoICT, 2015
  10. Semaphore elements NLT, SoICT, 2015
  11. Defining semaphore  Elements of semaphores assigned by the kernel  Semaphore control block (SCB)  Semaphore ID (unique in the system)  Value (binary or count)  Task-waiting list  Classification of semaphores:  Binary semaphore  Counting semaphore  Mutex NLT, SoICT, 2015
  12. Binary semaphore  Provides binary state of unavailable/available (or empty/full) Task 1 Task 2 Can’t acquire semaphore during Task 1’s Acquire semaphore acquirement (P operation) Acquire Releasesemaphore semaphore(P Release semaphore operation) (V operation) (V operation) Semaphore value value1: value Initial 0:available value1: 1: available available unavailable Task 3 Any tasks can release semaphore if it is global resource NLT, SoICT, 2015
  13. Counting semaphore  If the value of a semaphore is n, it can be acquired n times concurrently. NLT, SoICT, 2015
  14. Mutual exclusion (MUTEX) semaphores  Special binary semaphore  Has states of locked/unlocked & lock count  Difference: signaling vs protecting NLT, SoICT, 2015
  15. Mutual exclusion (MUTEX) semaphores  Special features of MUTEX  Ownership: When a task acquires the mutex, no other task can release it. - General semaphores: released by any task  Recursive locking: allows the owner task to re-acquire the mutex multiple times in the locked state - The number of times of recursive acquirement is managed by lock count. - Useful when the owner task requires exclusive access to shared resource and calls routines that also require the same resource - Problem: recursion and deadlock NLT, SoICT, 2015
  16. Mutual exclusion (MUTEX) semaphores  Special features of MUTEX  Task deletion safety: avoiding a task deletion while it is locking a mutex  Priority inversion avoidance: - Priority inversion problem: a higher priority task is blocked and is waiting for a resource being used by a lower priority task, which has itself been preempted by an unrelated medium-priority task - To avoid priority inversion additional protocols are required, eg priority inheritance protocol, or priority ceiling protocol NLT, SoICT, 2015
  17. Semaphore vs Mutex All processes can release semaphore Only owner is able to unlock mutex NLT, SoICT, 2015
  18. Typical semaphore use  Semaphore are used for:  Synchronizing execution of tasks  Coordinating access to a shared resource  Synchronization design requirements  Wait-and-signal  Multiple-task wait-and-signal  Credit-tracking  Single shared-resource-access  Recursive shared-resource-access  Multiple shared-resource access NLT, SoICT, 2015
  19. Typical semaphore uses NLT, SoICT, 2015
  20. Example:  Consumer – producer problem  Producer:  Task to read data from input device,  Data transferred to 4KB shared buffer memory  Consumer:  Task to read and process data from buffer memory  Synchronization problem  Solution 1: binary semaphore for buffer memory access  Other solution? NLT, SoICT, 2015
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2