If the lock was obtained, the lock must be unlocked with unlock() before another thread can successfully lock it for writing. The lock attempt will fail if another thread has locked for writing. If the lock was obtained, this function returns true, otherwise it returns false instead of waiting for the lock to become available, i.e. bool QReadWriteLock:: tryLockForRead()Īttempts to lock for reading. See also unlock(), lockForRead(), and tryLockForWrite(). It is not possible to lock for write if the thread already has locked for read. This function will block the current thread if another thread (including the current) has locked for reading or writing (unless the lock has been created using the QReadWriteLock::Recursive mode). See also unlock(), lockForWrite(), and tryLockForRead(). It is not possible to lock for read if the thread already has locked for write. This function will block the current thread if another thread has locked for writing. Warning: Destroying a read-write lock that is in use may result in undefined behavior. See also QReadLocker, QWriteLocker, QMutex, and QSemaphore. it is not possible to lock for reading in a thread that already has locked for writing (and vice versa). Note that the lock type cannot be changed when trying to lock recursively, i.e. In such cases, unlock() must be called the same number of times lockForWrite() or lockForRead() was called. Like QMutex, a QReadWriteLock can be recursively locked by the same thread when constructed with QReadWriteLock::Recursive as QReadWriteLock::RecursionMode. Also, if the lock is accessed by a writer and another writer comes in, that writer will have priority over any readers that might also be waiting. To ensure that writers aren't blocked forever by readers, readers attempting to obtain a lock will not succeed if there is a blocked writer waiting for access, even if the lock is currently only accessed by other readers.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |