tailieunhanh - Real-Time Embedded Multithreading Using ThreadX and MIPS- P10
Real-Time Embedded Multithreading Using ThreadX and MIPS- P10:Although the history of embedded systems is relatively short, 1 the advances and successes of this fi eld have been profound. Embedded systems are found in a vast array of applications such as consumer electronics, “ smart ” devices, communication equipment, automobiles, desktop computers, and medical equipment. | 182 Chapter 11 TX_SEMAPHORE my_semaphore UINT status Create a counting semaphore with an initial value of 1. This is typically the technique used to create a binary semaphore. Binary semaphores are used to provide protection over a common resource. status tx_semaphore_create my_semaphore my_semaphore_name 1 If status equals TX_SUCCESS my_semaphore is ready for use. Figure Creating a counting semaphore TX_SEMAPHORE my_semaphore UINT status Delete counting semaphore. Assume that the counting semaphore has already been created. status tx_semaphore_delete my_semaphore If status equals TX_SUCCESS the counting semaphore has been deleted. Figure Deleting a counting semaphore receive a TX_DELETED return status. Make certain that you don t try to use a deleted semaphore. Figure shows how a counting semaphore can be deleted. If variable status contains the return value TX_SUCCESS we have successfully deleted the counting semaphore. Getting an Instance of a Counting Semaphore The tx_semaphore_get service retrieves an instance a single count from the specified counting semaphore. If this call succeeds the semaphore count decreases by one. Figure shows how to get an instance of a counting semaphore where we use the wait option value TX_WAIT_FOREVER. If variable status contains the return value TX_SUCCESS we have successfully obtained an instance of the counting semaphore called my_semaphore. on to remove this watermark. Event Notification and Synchronization with Counting Semaphores 183 TX_SEMAPHORE my_semaphore UINT status Get a semaphore instance from the semaphore my_semaphore. If the semaphore count is zero suspend until an instance becomes available. Note that this suspension is only possible from application threads. status tx_semaphore_get my_semaphore TX_WAIT_FOREVER If status equals TX_SUCCESS the thread has obtained an instance of the semaphore. Figure Get an instance from a counting semaphore Retrieving Information .
đang nạp các trang xem trước