So there are three roles, three threads,
1. The UI, the main thread,
2. The model, the child thread A,
3. The serial port, the child thread B,
At any time to write a serial port to model data, the model according to the custom protocol unpacking, plus private material and algorithm, it is a logic, and then put into the cache, and UI read data from the model at any time,
Then the model of reading and writing must be locked, then write a serial port and avoid model, is to write locks, UI read, it is the lock, the UI will be lock gets stuck, is there a general way to avoid the UI will not be card?
I tried in reading data interface of the model, try_lock, then QApplication: : the processEvent (), to let the user interface (UI) to run the event when don't get the lock, but found more card, and I don't know is what reason, because I am just a simple example above, actually my project is very large, there are many other threads characters will call read data interface of the model, is not only the UI thread,
CodePudding user response:
Why the UI thread to lock. Try_lock although I don't know why, but certainly time consuming, the timeout is returned said "on the lock is not" return values, many a mickle makes a muckle, and UI is cardTo add a child no longer thread C reading model, when finish read want to display data, to update the data, tell the UI update
CodePudding user response: