How to define threads and message exchange

hi all,

I am doing a design of electronic parking system with two RS232 card reader, ethernet connection and local command input with keypad , I need to scan the token in the two readers antenna, process the token by business logic rule, store locally and upload transaction , and download fare rules from the server via ftp.
the threads I defined is below:
1, networking write thread for sending data transaction to server and response data for the requested command from server.
2, networking read thread for receiving the command requested by server and response for the requested command locally.
3, token reader write thread for sending the token command to the token.
4, token reader read thread for for receiving the token response.
5, business logic rule thread for token processing.
6, display thread for information display.

It needs the timer to monitor the communication timeout and repeat to send the request when no response .

I intended to use convar and mutex for data exchange among threads and I will be very appreciated for the suggestion on realizing it or any other proposal.

regards,
Shilunz

Welcome to QNX. QNX has a very powerful syncronous message passing architecture which works very well for more applications. You have not indicated any reason why you can’t have a collection of small apps which share information through message passing.

Once you get into a bunch of threads, you have something which is harder to debug and suffers from system failure if the bug in one thread, takes out the whole app.

Yes, you can do it with a bunch of threads, but this is not a circumstance where it is needed. I tend to use threads when they are appropriate for the problem I am trying to solve, and almost never as the first choice.

Rick…

Hi Rick,

 Thanks a lot.

  Previously I tried to do the testing with semaphore and shared memory, I found that some threads lost the CPU execution if threads assigned different priority, and I could see the expected result if threads at the same prioroty level.

1, Network comunication thread: read/write data from/to network

while(1)
{
if sem_trywait() =OK
read shm
write data to network
select( rfd, interval)
if data ready
read data from socket
if timeout
resend data

}  

2,token redaer thread :read/write token
similar to network thread.

as you can see that there is no blocking in the threads, I would like to know how to make the thread be blocked , send the requested data from the other threads
to the network and receive the data from outside.

regards,

shilunz

RK’s new book have a charpter talking about this. It explains
the how to make the decision to seperated jobs into processes
and threads.

Very useful informations.