Книга: Real-Time Concepts for Embedded Systems

7.7.3 Interlocked, Two-Way Data Communication

7.7.3 Interlocked, Two-Way Data Communication

Sometimes data must flow bidirectionally between tasks, which is called interlocked, two-way data communication (also called full-duplex or tightly coupled communication). This form of communication can be useful when designing a client/server-based system. A diagram is provided in Figure 7.8.


Figure 7.8: Interlocked, two-way data communication.

Listing 7.2: Pseudo code for interlocked, one-way data communication.

tSourceTask() {
 :
 Send message to message queue
 Acquire binary semaphore
 :
}
tSinkTask () {
 :
 Receive message from message queue
 Give binary semaphore
 :
}

In this case, tClientTask sends a request to tServerTask via a message queue. tServer-Task fulfills that request by sending a message back to tClientTask.

The pseudo code is provided in Listing 7.3.

Listing 7.3: Pseudo code for interlocked, two-way data communication.

tClientTask () {

 :
 Send a message to the requests queue
 Wait for message from the server queue
 :
}
tServerTask () {
 :
 Receive a message from the requests queue
 Send a message to the client queue
 :
}

Note that two separate message queues are required for full-duplex communication. If any kind of data needs to be exchanged, message queues are required; otherwise, a simple semaphore can be used to synchronize acknowledgement.

In the simple client/server example, tServerTask is typically set to a higher priority, allowing it to quickly fulfill client requests. If multiple clients need to be set up, all clients can use the client message queue to post requests, while tServerTask uses a separate message queue to fulfill the different clients’ requests.

Оглавление книги


Генерация: 2.293. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз