compie
June 29, 2007, 12:00pm
21
Is the following code ok?
I’m using:
two threads
one TCP socket
one mutex to protect the socket
one queue that will be filled with data when something needs to be sent. (the tx_queue_send() calls are done by other threads).
TCP Receive thread:
while(true)
{
select(socket,readset) //wait for data to arrive on the socket
tx_mutex_get()
recv()
tx_mutex_put()
}
TCP Send thread:
while(true)
{
tx_queue_receive() //wait for data to be sent
tx_mutex_get()
send()
tx_mutex_put()
}
other threads:
tx_queue_send() //when some data needs to be sent
The pseudo code looks fine as far as I can tell.
Looks good to me. Just make sure you use those mutexes in the FIFO queue as well so threads don’t overwrite each other.
-Erik
compie
July 2, 2007, 11:03am
24
I’m pretty sure tx_queue_send() is reentrant, so it doesn’t need a mutex to make it a critical section.
Whoops! Sorry. I didn’t know it was a built in API. I just assumed that these were your functions. Must be a new API, I haven’t seen it before. I wrote those functions for myself.
-Erik
compie
July 9, 2007, 8:31am
26
All functions starting with tx_ are ThreadX functions. ThreadX is the real-time kernel used in NET+OS 7.1
See http://www.rtos.com/page/product.php?id=2