Any suggestions for the questions about the second thread?
Any suggestions for the questions about the second thread?
You don't need a thread for that, you can use processEvents() in your lengthy task.Hi high_flyer, I missed to say that both threads doesnt' run at the same time. Each of both runs in different moments of the application. And it's strongly needed a thread for the first case because I need to do a very lengthy operation on background, while in the main thread the user can do another things.
In general threads are needed when more then one task needs to be executed in prallel.
Is this the case you have?
I am not sure from what you said till now...
Again, if the cpu stays in one thread, you don't need threads, as threads are used when you want other processes to work in parallel, i.e CPU switches between them.The reason that I don't use a mutex while I consult/modify the shared boolean in the first thread is because these operations are done in just one machine instruction so the cpu never changes the current operating thread while these operations are executed and that's why I think that never could cause a problem, am I wrong?
As answer to what you said, here, is that you can't really know/ have control over what the CPU does so your statmet may or may not be true, depends on the system and your application.
thanxs high_flyer for your suggestions
That's not quite true. The setting and getting of his boolean variable will be an atomic instruction and hence thead-safe. He may need a mutex though if he has a function that sets/gets the value and then executes further statements that depend on the value not having changed.Originally Posted by high_flyer
Save yourself some pain. Learn C++ before learning Qt.
What I said is true, and has nothing to do with atomic instructions but with the fact that if the CPU is doing a task (not instruction) where it is not needed to share CPU time with other tasks, threads are not needed.
I was referring to the second part of your statement, not the first.
Save yourself some pain. Learn C++ before learning Qt.
Bookmarks