I am new to vc++.I am developing an application.In that I have to
write a command to the serial port and I will be getting
acknowledgments for all the commands and in addition to ack I will be
getting som responses from the other side of the port in which case I
have to write back the ack.
For this need I have two threads running.One thread-write only will be
writing the command to the port,other thread-read-writewill be reading
the port and processing and if needed writes back the ack.
In had a sleep of 1 in the second thread where both read-write is
combined.Actually when the other side sends back the response,it is not
getting the ack from my side within 250 ms with 9600 baudrate and it is
timing out and starts retransmitting for 3 times.But in the mean time
my read operation is going on and i am sending back the ack.In this
case where my retransmission from the other side happens,when the write
thread sends next command followed by the read-write thread expecting
the ack from the other side and is reading the previous retransmitted
data and not the present ack.
My Question is
1)Why my read-write thread is taking so much time to send back ack
2)Do I need to implement any semaphore in synchronization of the
I tried with removing the sleep in the read-write thread.But it is
sending the ack back before the 250ms.I know this will create problem
since my both threads will be running and create problem.But somehow
there isno problem.But how?
Can anyone clarify me and give the proper solution