I have software for a BERT that networks with a external database (SMU). The program requests information from the SMU and waits for a response. Sometimes, the software hangs while waiting for the information.
To prevent the program from hanging, I decided to create a threading system such that a timer will indicate if the read procedure is hung. If this is so, the program will have to cancel the read and perform some analysis.
I decided that the program will spawn a thread to perform the IO. Then start a timer for a period of time. Once the thread is done, it will terminate. If the thread still exists, the program will terminate it and the program will behave accordingly.
I need some advice as to what to consider. I'm not very skilled with threads since I don't have much applied knowledge. I read that I should use KLT to prevent the whole program from being blocked. So how will my program know if its thread has finished? Should I have flags inside the IO thread that indicate if read happened or not? Should I have two threads, one for keeping the time and one for reading? Then should the program should check if expired flag is set or the read flag is set and behave accordingly?
Sorry if this question is confusing. I know the outcome I want but have so many ideas to obtain it without the wisdom of what is acheivable.
To prevent the program from hanging, I decided to create a threading system such that a timer will indicate if the read procedure is hung. If this is so, the program will have to cancel the read and perform some analysis.
I decided that the program will spawn a thread to perform the IO. Then start a timer for a period of time. Once the thread is done, it will terminate. If the thread still exists, the program will terminate it and the program will behave accordingly.
I need some advice as to what to consider. I'm not very skilled with threads since I don't have much applied knowledge. I read that I should use KLT to prevent the whole program from being blocked. So how will my program know if its thread has finished? Should I have flags inside the IO thread that indicate if read happened or not? Should I have two threads, one for keeping the time and one for reading? Then should the program should check if expired flag is set or the read flag is set and behave accordingly?
Sorry if this question is confusing. I know the outcome I want but have so many ideas to obtain it without the wisdom of what is acheivable.
Comment