PDA

View Full Version : both two slots modify data model, use lock to sync?



justDance
29th October 2012, 01:23
two threads emit two different signals to main thread two slots, both two slots modify data model, I'm using lock to sync, and testing now. So far no problem. Is this the right design?

Thanks,

ChrisW67
29th October 2012, 01:49
Starting two threads on the same problem will not increase the odds of an answer.

The answer is a resounding "Maybe". Using signals/slots to carry data between threads is good; with copies being transmitted and queued. You should not need locking mechanisms if all your data structures are only accessed from the owning thread (e.g. in slot code). There are devils in the detail though... and we cannot see the detail.

justDance
29th October 2012, 03:03
Thank you Chris. Make sense. Since the two slots are in the same thread, it is not possible that they will be called and access the data model at the same time. so no need to use lock.

Could you please have a look at my another design question:
http://www.qtcentre.org/threads/51789-design-question-about-MVC-with-multithreading

thanks,