[Solved] Why Qt has so limited synchronization possibilities comparing with WinAPI?
-
Hi.
I started to check QThread, QWaitCondition, QMutex classes. And, in my opinion, they haven't some very useful possibilities, which are under Windows:
WaitForMultipleObjects - where I can wait one only kernel object from several, not all of them;
Check Wait... function for WAIT_ABANDONED - not to lock waiting thread if master (current owner of the mutex) died, but did not release mutex;
CreateEvent - event objects are very good for cross-synchronization with exact thread sequence. And named kernel objects - not to launch second instance of app.
Access to thread, process handles - to wait untill they finished theyr job..
Why all of them are not implemented?
Or these functionalities are hidden in another classes? -
Hi,
There are many more classes than that. See "Thread Support in Qt":http://doc-snapshot.qt-project.org/qt5-stable/threads.html for a list of all available classes. See "Multithreading Technologies in Qt":http://doc-snapshot.qt-project.org/qt5-stable/threads-technologies.html for an overview of different ways to use threads.
Also, remember that Qt is a cross-platform framework. It provides high-level APIs, not low-level kernel accessors.
[quote]WaitForMultipleObjects – where I can wait one only kernel object from several, not all of them;[/quote]See QFutureSynchronizer.
[quote]Check Wait… function for WAIT_ABANDONED – not to lock waiting thread if master (current owner of the mutex) died, but did not release mutex;[/quote]If a program produces abandoned mutexes, then the program is broken. That's why AbandonedMutexException exists -- abandoned mutexes are exceptions (errors).
Use QMutexLocker instead. It will guarantee that a mutex is released when a thread dies.
[quote]CreateEvent – event objects are very good for cross-synchronization with exact thread sequence.[/quote]Qt is an event-driven framework and uses events are everywhere. First, read about "Signals and Slots":http://qt-project.org/doc/qt-5.1/qtcore/signalsandslots.html, which extend the event system. Then, read about "how to use the event system for inter-thread communication":http://doc-snapshot.qt-project.org/qt5-stable/threads-synchronizing.html#high-level-event-queues.
[quote]And named kernel objects – not to launch second instance of app.[/quote]Yes, that would be a nice feature. It's unrelated to synchronization/multithreading though.
[quote]Access to thread, process handles – to wait untill they finished theyr job[/quote]
- QThread::currentThread()
- QThread::wait()
By the way, you talked about waiting a lot. If you are designing a new program, I encourage you to start using signals and slots. This is taken from the QThread documentation:
"Note: wait() and the sleep() functions should be unnecessary in general, since Qt is an event-driven framework. Instead of wait(), consider listening for the finished() signal. Instead of the sleep() functions, consider using QTimer."
[quote]Why all of them are not implemented?[/quote]Please read the documentation carefully before declaring that functions aren't implemented and the framework is limited.
-
@JKSH -Thanks for mentioned classes and links. But...
[quote] Please read the documentation carefully before declaring that functions aren't implemented and the framework is limited.[/quote]There is no need to be so rude... In my post there are no insults in address of Qt. Look at a title - It is a question, not a statement. And after reading carefully documentation during several hours, and looking for info in forum posts all evening, I think I have a right to ask something. A couple years ago I worked in a company where we used our own thread library. And I was responsible for it architecture and several classes. And in analogy I looked for mentioned functionality in Qt classes, which, I think, should have it.
At the end of my post I sincerely asked: "Or these functionalities are hidden in another classes? ". Qt, C#, Java have a lot of classes, and to read, try and understand them there is a need for much bigger free time. In a production, as you know, it is a luxury. After working a lot of time in one language or lib, and switching on another - the most common question - "Where did they hide all this stuff?"
So, please, try to respect newcommers to Qt, and be a little more polite. -
Hi aiJudgementF,
I'm sorry for being rude, and for ignoring your last question. Thank you for explaining your background. You're right: free time is a luxury, so it was unfair of me to expect you to find all the information beforehand.
Your questions were "loaded questions":http://en.wikipedia.org/wiki/Loaded_question, however: "Why Qt has so limited synchronization possibilities?" and "Why all of them are not implemented?" have very different meanings from "Where did they hide all this stuff?". I made my last statement because I assumed that you were trying to hide statements inside loaded questions (which is done often, and it's considered a logical fallacy), but that was an unfair assumption too. Again, I apologize.
Let's start over.
Welcome to the Qt community. I hope that you find Qt useful in your projects. If you have any questions, feel free to ask and I'm sure someone here will be happy to help you out!
-
Ok, accepted.
In turn, I must admit, that my question should be sound more like "Where did they hide all this stuff?". I my another post <Exception at ... code: 0xc0000138> you are helping me a lot. Thanks!!!
And I hope, I could help you in some field too. :-)