\hypertarget{class_qore_1_1_thread_1_1_r_w_lock}{}\section{Qore\+:\+:Thread\+:\+:R\+W\+Lock Class Reference}
\label{class_qore_1_1_thread_1_1_r_w_lock}\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}


The \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} class implements a read-\/write thread lock.  




Inheritance diagram for Qore\+:\+:Thread\+:\+:R\+W\+Lock\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=258pt]{class_qore_1_1_thread_1_1_r_w_lock__inherit__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a2cca11879044ef7f40cfa707f1bf3c47}{constructor} ()
\begin{DoxyCompactList}\small\item\em Creates the \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} object. \end{DoxyCompactList}\item 
\hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a88a6fefec6f761cf0d72baf2b38cb62b}{copy} ()
\begin{DoxyCompactList}\small\item\em Creates a new \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} object, not based on the original. \end{DoxyCompactList}\item 
\hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a52ba1405c9bf97c3888cc58bd0d5902a}{destructor} ()
\begin{DoxyCompactList}\small\item\em Destroys the \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} object. \end{DoxyCompactList}\item 
\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_acb76cd08c7aa13854b2174e952efee65}{get\+Read\+Waiting} ()
\begin{DoxyCompactList}\small\item\em Returns the number of threads waiting on the read lock. \end{DoxyCompactList}\item 
\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_ab5f9f093afb74f047051356524e288ff}{get\+Write\+Waiting} ()
\begin{DoxyCompactList}\small\item\em Returns the number of threads waiting on the write lock. \end{DoxyCompactList}\item 
bool \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_aefcf3643bfe193b7d4b63cef41299ade}{lock\+Owner} ()
\begin{DoxyCompactList}\small\item\em Returns \hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the current thread is holding either the read lock or the write lock, \hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False} if not. \end{DoxyCompactList}\item 
\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a5ae6ade327e6c65430025c653c684f3c}{num\+Readers} ()
\begin{DoxyCompactList}\small\item\em Returns the read lock count. \end{DoxyCompactList}\item 
nothing \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_ad8ab081b2f254129ec042d614fbb1485}{read\+Lock} ()
\begin{DoxyCompactList}\small\item\em Acquires the read lock; blocks if the write lock is already acquired by another thread. \end{DoxyCompactList}\item 
\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a10e4f61ecbb32380ac729217cb6b3161}{read\+Lock} (timeout timeout\+\_\+ms)
\begin{DoxyCompactList}\small\item\em Acquires the read lock with a timeout value; blocks if the write lock is already acquired by another thread. \end{DoxyCompactList}\item 
bool \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a362a40fe4d167e29befa94f40e4495e5}{read\+Lock\+Owner} ()
\begin{DoxyCompactList}\small\item\em Returns \hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the current thread is holding the read lock, \hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False} if not. \end{DoxyCompactList}\item 
nothing \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a1a32805ce5cc129d2ed2bf96b01a7d4c}{read\+Unlock} ()
\begin{DoxyCompactList}\small\item\em Decrements the read lock counter and releases the read lock if the counter is zero. If at least one thread is blocked trying to acquire the write lock and the read counter reaches zero, then one thread waiting on the write lock is woken up. \end{DoxyCompactList}\item 
\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_ae6ae2fb6dadf5d144dbd7694c0ca0bfb}{try\+Read\+Lock} ()
\begin{DoxyCompactList}\small\item\em Acquires the read lock only if it can be acquired immediately. \end{DoxyCompactList}\item 
\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a20b09807edecf2ee7591e90e16c4fe6c}{try\+Write\+Lock} ()
\begin{DoxyCompactList}\small\item\em Acquires the write lock only if it can be acquired immediately. \end{DoxyCompactList}\item 
\hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a0be2f09ba84a3a5fbf3d0073c59f8542}{write\+Lock} (timeout timeout\+\_\+ms)
\begin{DoxyCompactList}\small\item\em Acquires the write lock with a timeout value; blocks if the read lock is already acquired by another thread. \end{DoxyCompactList}\item 
nothing \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a15face42a9f0634de3e2f835f8daa35b}{write\+Lock} ()
\begin{DoxyCompactList}\small\item\em Acquires the write lock; blocks if the read lock is already acquired by another thread. \end{DoxyCompactList}\item 
bool \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a5e9c32cc40cd0cb9b00e6d29f265884f}{write\+Lock\+Owner} ()
\begin{DoxyCompactList}\small\item\em Returns \hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the current thread is holding the write lock, \hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False} if not. \end{DoxyCompactList}\item 
nothing \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a577f98df56071f39199c7ace72dc132d}{write\+Unlock} ()
\begin{DoxyCompactList}\small\item\em Releases the write lock, if any readers are waiting, wakes up all readers, otherwise if any writers are waiting, then wakes one up. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
The \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} class implements a read-\/write thread lock. 

\begin{DoxyParagraph}{Restrictions\+:}
\hyperlink{group__parse__options_gade963e1fbbd1f5b2c777df7221512a1b}{Qore\+::\+P\+O\+\_\+\+N\+O\+\_\+\+T\+H\+R\+E\+A\+D\+\_\+\+C\+L\+A\+S\+S\+ES}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Overview}
This class inherits \hyperlink{class_qore_1_1_thread_1_1_abstract_smart_lock}{Abstract\+Smart\+Lock}, so it can be used by \hyperlink{class_qore_1_1_thread_1_1_condition}{Condition} objects, while using either the read lock or the write lock.~\newline
~\newline
 The \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} class implements a read-\/write lock for efficient thread locking when write actions must be atomic and reads can be made in parallel if no write is in progress. When a thread holds the write lock, no other thread can grab the read or write lock. Multiple threads can hold the read lock at one time.~\newline
~\newline
 As with all Qore threading primitives, this class supports deadlock detection and throws exceptions when threading errors are encountered (for example, trying to free the read lock while holding the write lock, etc).~\newline
~\newline
 This read-\/write lock favors readers, so the read lock can be safely acquired recursively.~\newline
~\newline
 See the \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} and the \hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock} classes for classes that assist in exception-\/safe \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} locking.~\newline
~\newline
 Additionally, the \hyperlink{statements_on_exit}{on\+\_\+exit statement} can provide exception-\/safe \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} handling at the lexical block level as in the following example\+: 
\begin{DoxyCode}
\{
    rwl.writeLock();
    on\_exit
        rwl.writeUnlock();

    \textcolor{comment}{# ... when this block exits the lock will be released, even in the}
    \textcolor{comment}{#     case of return statements or exceptions}
\}
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxyParagraph}{Thread Resource Handling}
The \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} class manages the lock as a \hyperlink{threading_thread_resources}{thread resource}; if the lock is not released when the thread exits (or when \hyperlink{group__threading__functions_ga421dca39ccb55b191d5d09fd98c2075a}{Qore\+::throw\+\_\+thread\+\_\+resource\+\_\+exceptions()} or \hyperlink{group__threading__functions_ga4e62409b8a1b414276d033267e7299e4}{Qore\+::throw\+\_\+thread\+\_\+resource\+\_\+exceptions\+\_\+to\+\_\+mark()} is called), the any read or write locks held are released automatically and a {\ttfamily L\+O\+C\+K-\/\+E\+R\+R\+OR} exception is thrown describing the situation.~\newline
~\newline
 Being an builtin class, the \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} class does not inherit \hyperlink{class_qore_1_1_thread_1_1_abstract_thread_resource}{Abstract\+Thread\+Resource} explicitly as a part of the exported A\+PI, and the internal \hyperlink{class_qore_1_1_thread_1_1_abstract_thread_resource_a0431f7384991eaf6900ee3a952b57f87}{Abstract\+Thread\+Resource\+:\+:cleanup()} method cannot be overridden or suppressed.
\end{DoxyParagraph}
\begin{DoxyNote}{Note}
This class is not available with the \hyperlink{group__parse__options_gade963e1fbbd1f5b2c777df7221512a1b}{P\+O\+\_\+\+N\+O\+\_\+\+T\+H\+R\+E\+A\+D\+\_\+\+C\+L\+A\+S\+S\+ES} parse option. 
\end{DoxyNote}


\subsection{Member Function Documentation}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a2cca11879044ef7f40cfa707f1bf3c47}\label{class_qore_1_1_thread_1_1_r_w_lock_a2cca11879044ef7f40cfa707f1bf3c47}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!constructor@{constructor}}
\index{constructor@{constructor}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{constructor()}{constructor()}}
{\footnotesize\ttfamily Qore\+::\+Thread\+::\+R\+W\+Lock\+::constructor (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Creates the \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} object. 

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
RWLock rwl();
\end{DoxyCode}
 
\end{DoxyParagraph}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a88a6fefec6f761cf0d72baf2b38cb62b}\label{class_qore_1_1_thread_1_1_r_w_lock_a88a6fefec6f761cf0d72baf2b38cb62b}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!copy@{copy}}
\index{copy@{copy}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{copy()}{copy()}}
{\footnotesize\ttfamily Qore\+::\+Thread\+::\+R\+W\+Lock\+::copy (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Creates a new \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} object, not based on the original. 

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
RWLock new\_rwl = rwl.copy();
\end{DoxyCode}
 
\end{DoxyParagraph}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a52ba1405c9bf97c3888cc58bd0d5902a}\label{class_qore_1_1_thread_1_1_r_w_lock_a52ba1405c9bf97c3888cc58bd0d5902a}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!destructor@{destructor}}
\index{destructor@{destructor}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{destructor()}{destructor()}}
{\footnotesize\ttfamily Qore\+::\+Thread\+::\+R\+W\+Lock\+::destructor (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Destroys the \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} object. 

Note that it is a programming error to delete this object while other threads are blocked on it; in this case an exception is thrown in the deleting thread, and in each thread blocked on this object when it is deleted.

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
delete rwl;
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em L\+O\+C\+K-\/\+E\+R\+R\+OR} & Object deleted while other threads blocked on it \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_acb76cd08c7aa13854b2174e952efee65}\label{class_qore_1_1_thread_1_1_r_w_lock_acb76cd08c7aa13854b2174e952efee65}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!get\+Read\+Waiting@{get\+Read\+Waiting}}
\index{get\+Read\+Waiting@{get\+Read\+Waiting}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{get\+Read\+Waiting()}{getReadWaiting()}}
{\footnotesize\ttfamily \hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} Qore\+::\+Thread\+::\+R\+W\+Lock\+::get\+Read\+Waiting (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Returns the number of threads waiting on the read lock. 

\begin{DoxyReturn}{Returns}
the number of threads waiting on the read lock
\end{DoxyReturn}
\begin{DoxyParagraph}{Code Flags\+:}
\hyperlink{code_flags_CONSTANT}{C\+O\+N\+S\+T\+A\+NT}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
int num = rwl.getReadWaiting();
\end{DoxyCode}
 
\end{DoxyParagraph}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_ab5f9f093afb74f047051356524e288ff}\label{class_qore_1_1_thread_1_1_r_w_lock_ab5f9f093afb74f047051356524e288ff}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!get\+Write\+Waiting@{get\+Write\+Waiting}}
\index{get\+Write\+Waiting@{get\+Write\+Waiting}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{get\+Write\+Waiting()}{getWriteWaiting()}}
{\footnotesize\ttfamily \hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} Qore\+::\+Thread\+::\+R\+W\+Lock\+::get\+Write\+Waiting (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Returns the number of threads waiting on the write lock. 

\begin{DoxyReturn}{Returns}
the number of threads waiting on the write lock
\end{DoxyReturn}
\begin{DoxyParagraph}{Code Flags\+:}
\hyperlink{code_flags_CONSTANT}{C\+O\+N\+S\+T\+A\+NT}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
int num = rwl.getWriteWaiting();
\end{DoxyCode}
 
\end{DoxyParagraph}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_aefcf3643bfe193b7d4b63cef41299ade}\label{class_qore_1_1_thread_1_1_r_w_lock_aefcf3643bfe193b7d4b63cef41299ade}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!lock\+Owner@{lock\+Owner}}
\index{lock\+Owner@{lock\+Owner}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{lock\+Owner()}{lockOwner()}}
{\footnotesize\ttfamily bool Qore\+::\+Thread\+::\+R\+W\+Lock\+::lock\+Owner (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Returns \hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the current thread is holding either the read lock or the write lock, \hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False} if not. 

\begin{DoxyReturn}{Returns}
\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the current thread is holding either the read lock or the write lock, \hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False} if not
\end{DoxyReturn}
\begin{DoxyParagraph}{Code Flags\+:}
\hyperlink{code_flags_CONSTANT}{C\+O\+N\+S\+T\+A\+NT}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
\textcolor{keywordflow}{if} (rwl.lockOwner())
    \hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}(\textcolor{stringliteral}{"TID %d has either the read lock or the write lock\(\backslash\)n"}, \hyperlink{group__threading__functions_ga95ed8e572309b44b3f5b49673238c3e6}{gettid}());
\end{DoxyCode}
 
\end{DoxyParagraph}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a5ae6ade327e6c65430025c653c684f3c}\label{class_qore_1_1_thread_1_1_r_w_lock_a5ae6ade327e6c65430025c653c684f3c}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!num\+Readers@{num\+Readers}}
\index{num\+Readers@{num\+Readers}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{num\+Readers()}{numReaders()}}
{\footnotesize\ttfamily \hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} Qore\+::\+Thread\+::\+R\+W\+Lock\+::num\+Readers (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Returns the read lock count. 

\begin{DoxyReturn}{Returns}
the read lock count
\end{DoxyReturn}
\begin{DoxyParagraph}{Code Flags\+:}
\hyperlink{code_flags_CONSTANT}{C\+O\+N\+S\+T\+A\+NT}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
int num = rwl.numReaders();
\end{DoxyCode}
 
\end{DoxyParagraph}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_ad8ab081b2f254129ec042d614fbb1485}\label{class_qore_1_1_thread_1_1_r_w_lock_ad8ab081b2f254129ec042d614fbb1485}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!read\+Lock@{read\+Lock}}
\index{read\+Lock@{read\+Lock}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{read\+Lock()}{readLock()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily nothing Qore\+::\+Thread\+::\+R\+W\+Lock\+::read\+Lock (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Acquires the read lock; blocks if the write lock is already acquired by another thread. 

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
rwl.readLock();
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em T\+H\+R\+E\+A\+D-\/\+D\+E\+A\+D\+L\+O\+CK} & A deadlock was detected while trying to acquire the lock \\
\hline
{\em L\+O\+C\+K-\/\+E\+R\+R\+OR} & \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_ad8ab081b2f254129ec042d614fbb1485}{R\+W\+Lock\+::read\+Lock()} called while already holding the write lock, object deleted in another thread, etc. \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a10e4f61ecbb32380ac729217cb6b3161}\label{class_qore_1_1_thread_1_1_r_w_lock_a10e4f61ecbb32380ac729217cb6b3161}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!read\+Lock@{read\+Lock}}
\index{read\+Lock@{read\+Lock}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{read\+Lock()}{readLock()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily \hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} Qore\+::\+Thread\+::\+R\+W\+Lock\+::read\+Lock (\begin{DoxyParamCaption}\item[{timeout}]{timeout\+\_\+ms }\end{DoxyParamCaption})}



Acquires the read lock with a timeout value; blocks if the write lock is already acquired by another thread. 

Returns 0 for success, non-\/zero for timeout; exceptions are thrown for other errors


\begin{DoxyParams}{Parameters}
{\em timeout\+\_\+ms} & a \hyperlink{data_type_declarations_timeout_type}{timeout} value to wait to acquire the read lock; integers are interpreted as milliseconds; \hyperlink{basic_data_types_relative_dates}{relative date/time values} are interpreted literally (with a resolution of milliseconds)\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 for success, non-\/zero for timeout; exceptions are thrown for other errors
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
\textcolor{keywordflow}{if} (rwl.readLock(1500ms))
    throw \textcolor{stringliteral}{"TIMEOUT"}, \textcolor{stringliteral}{"timed out after 1.5s waiting for the read lock"};
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em T\+H\+R\+E\+A\+D-\/\+D\+E\+A\+D\+L\+O\+CK} & A deadlock was detected while trying to acquire the lock \\
\hline
{\em L\+O\+C\+K-\/\+E\+R\+R\+OR} & \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_ad8ab081b2f254129ec042d614fbb1485}{R\+W\+Lock\+::read\+Lock()} called while already holding the write lock, object deleted in another thread, etc. \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a362a40fe4d167e29befa94f40e4495e5}\label{class_qore_1_1_thread_1_1_r_w_lock_a362a40fe4d167e29befa94f40e4495e5}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!read\+Lock\+Owner@{read\+Lock\+Owner}}
\index{read\+Lock\+Owner@{read\+Lock\+Owner}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{read\+Lock\+Owner()}{readLockOwner()}}
{\footnotesize\ttfamily bool Qore\+::\+Thread\+::\+R\+W\+Lock\+::read\+Lock\+Owner (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Returns \hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the current thread is holding the read lock, \hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False} if not. 

\begin{DoxyReturn}{Returns}
\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the current thread is holding the read lock, \hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False} if not
\end{DoxyReturn}
\begin{DoxyParagraph}{Code Flags\+:}
\hyperlink{code_flags_CONSTANT}{C\+O\+N\+S\+T\+A\+NT}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
\textcolor{keywordflow}{if} (rwl.readLockOwner())
    \hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}(\textcolor{stringliteral}{"TID %d has the read lock\(\backslash\)n"}, \hyperlink{group__threading__functions_ga95ed8e572309b44b3f5b49673238c3e6}{gettid}());
\end{DoxyCode}
 
\end{DoxyParagraph}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a1a32805ce5cc129d2ed2bf96b01a7d4c}\label{class_qore_1_1_thread_1_1_r_w_lock_a1a32805ce5cc129d2ed2bf96b01a7d4c}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!read\+Unlock@{read\+Unlock}}
\index{read\+Unlock@{read\+Unlock}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{read\+Unlock()}{readUnlock()}}
{\footnotesize\ttfamily nothing Qore\+::\+Thread\+::\+R\+W\+Lock\+::read\+Unlock (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Decrements the read lock counter and releases the read lock if the counter is zero. If at least one thread is blocked trying to acquire the write lock and the read counter reaches zero, then one thread waiting on the write lock is woken up. 

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
rwl.readUnlock();
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em L\+O\+C\+K-\/\+E\+R\+R\+OR} & \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a1a32805ce5cc129d2ed2bf96b01a7d4c}{R\+W\+Lock\+::read\+Unlock()} called while not holding the read lock, object deleted in another thread, etc \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_ae6ae2fb6dadf5d144dbd7694c0ca0bfb}\label{class_qore_1_1_thread_1_1_r_w_lock_ae6ae2fb6dadf5d144dbd7694c0ca0bfb}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!try\+Read\+Lock@{try\+Read\+Lock}}
\index{try\+Read\+Lock@{try\+Read\+Lock}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{try\+Read\+Lock()}{tryReadLock()}}
{\footnotesize\ttfamily \hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} Qore\+::\+Thread\+::\+R\+W\+Lock\+::try\+Read\+Lock (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Acquires the read lock only if it can be acquired immediately. 

\begin{DoxyReturn}{Returns}
0 for success (read lock acquired, read lock count incremented) or -\/1 if the call would block (write lock owned by another thread) or an error occured
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
\textcolor{keywordflow}{if} (!rwl.tryReadLock()) \{
    on\_exit rwl.readUnlock();
    do\_something\_in\_read\_lock();
\}
\end{DoxyCode}
 
\end{DoxyParagraph}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a20b09807edecf2ee7591e90e16c4fe6c}\label{class_qore_1_1_thread_1_1_r_w_lock_a20b09807edecf2ee7591e90e16c4fe6c}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!try\+Write\+Lock@{try\+Write\+Lock}}
\index{try\+Write\+Lock@{try\+Write\+Lock}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{try\+Write\+Lock()}{tryWriteLock()}}
{\footnotesize\ttfamily \hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} Qore\+::\+Thread\+::\+R\+W\+Lock\+::try\+Write\+Lock (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Acquires the write lock only if it can be acquired immediately. 

\begin{DoxyReturn}{Returns}
0 for success (write lock acquired) or -\/1 if the call would block (read lock owned by another thread) or an error occured 
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
\textcolor{keywordflow}{if} (!rwl.tryWriteLock()) \{
    on\_exit rwl.writeUnlock();
    do\_something\_in\_write\_lock();
\}
\end{DoxyCode}
 
\end{DoxyParagraph}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a0be2f09ba84a3a5fbf3d0073c59f8542}\label{class_qore_1_1_thread_1_1_r_w_lock_a0be2f09ba84a3a5fbf3d0073c59f8542}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!write\+Lock@{write\+Lock}}
\index{write\+Lock@{write\+Lock}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{write\+Lock()}{writeLock()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily \hyperlink{group__type__conversion__functions_ga2de8717e92c5f97ccc6511f6062d6502}{int} Qore\+::\+Thread\+::\+R\+W\+Lock\+::write\+Lock (\begin{DoxyParamCaption}\item[{timeout}]{timeout\+\_\+ms }\end{DoxyParamCaption})}



Acquires the write lock with a timeout value; blocks if the read lock is already acquired by another thread. 

Returns 0 for success, non-\/zero for timeout; exceptions are thrown for other errors


\begin{DoxyParams}{Parameters}
{\em timeout\+\_\+ms} & a \hyperlink{data_type_declarations_timeout_type}{timeout} value to wait to acquire the write lock; integers are interpreted as milliseconds; \hyperlink{basic_data_types_relative_dates}{relative date/time values} are interpreted literally (with a resolution of milliseconds)\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 for success, non-\/zero for timeout; exceptions are thrown for other errors
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
\textcolor{keywordflow}{if} (rwl.writeLock(1500ms))
    throw \textcolor{stringliteral}{"TIMEOUT"}, \textcolor{stringliteral}{"timed out after 1.5s waiting for the write lock"};
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em T\+H\+R\+E\+A\+D-\/\+D\+E\+A\+D\+L\+O\+CK} & A deadlock was detected while trying to acquire the lock \\
\hline
{\em L\+O\+C\+K-\/\+E\+R\+R\+OR} & \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a15face42a9f0634de3e2f835f8daa35b}{R\+W\+Lock\+::write\+Lock()} called while already holding the read lock, object deleted in another thread, etc. \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a15face42a9f0634de3e2f835f8daa35b}\label{class_qore_1_1_thread_1_1_r_w_lock_a15face42a9f0634de3e2f835f8daa35b}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!write\+Lock@{write\+Lock}}
\index{write\+Lock@{write\+Lock}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{write\+Lock()}{writeLock()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily nothing Qore\+::\+Thread\+::\+R\+W\+Lock\+::write\+Lock (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Acquires the write lock; blocks if the read lock is already acquired by another thread. 

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
rwl.writeLock();
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em T\+H\+R\+E\+A\+D-\/\+D\+E\+A\+D\+L\+O\+CK} & A deadlock was detected while trying to acquire the lock \\
\hline
{\em L\+O\+C\+K-\/\+E\+R\+R\+OR} & \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a15face42a9f0634de3e2f835f8daa35b}{R\+W\+Lock\+::write\+Lock()} called while already holding the read lock, object deleted in another thread, etc. \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a5e9c32cc40cd0cb9b00e6d29f265884f}\label{class_qore_1_1_thread_1_1_r_w_lock_a5e9c32cc40cd0cb9b00e6d29f265884f}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!write\+Lock\+Owner@{write\+Lock\+Owner}}
\index{write\+Lock\+Owner@{write\+Lock\+Owner}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{write\+Lock\+Owner()}{writeLockOwner()}}
{\footnotesize\ttfamily bool Qore\+::\+Thread\+::\+R\+W\+Lock\+::write\+Lock\+Owner (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Returns \hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the current thread is holding the write lock, \hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False} if not. 

\begin{DoxyReturn}{Returns}
\hyperlink{group__boolean__constants_ga3ba2df91713a6249449347131ea526c3}{True} if the current thread is holding the write lock, \hyperlink{group__boolean__constants_ga9da2b9a8003cd3788e48305f8a00540f}{False} if not
\end{DoxyReturn}
\begin{DoxyParagraph}{Code Flags\+:}
\hyperlink{code_flags_CONSTANT}{C\+O\+N\+S\+T\+A\+NT}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
\textcolor{keywordflow}{if} (rwl.writeLockOwner())
    \hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}(\textcolor{stringliteral}{"TID %d has the write lock\(\backslash\)n"}, \hyperlink{group__threading__functions_ga95ed8e572309b44b3f5b49673238c3e6}{gettid}());
\end{DoxyCode}
 
\end{DoxyParagraph}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_r_w_lock_a577f98df56071f39199c7ace72dc132d}\label{class_qore_1_1_thread_1_1_r_w_lock_a577f98df56071f39199c7ace72dc132d}} 
\index{Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}!write\+Unlock@{write\+Unlock}}
\index{write\+Unlock@{write\+Unlock}!Qore\+::\+Thread\+::\+R\+W\+Lock@{Qore\+::\+Thread\+::\+R\+W\+Lock}}
\subsubsection{\texorpdfstring{write\+Unlock()}{writeUnlock()}}
{\footnotesize\ttfamily nothing Qore\+::\+Thread\+::\+R\+W\+Lock\+::write\+Unlock (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Releases the write lock, if any readers are waiting, wakes up all readers, otherwise if any writers are waiting, then wakes one up. 

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
rwl.writeUnlock();
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em L\+O\+C\+K-\/\+E\+R\+R\+OR} & \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a577f98df56071f39199c7ace72dc132d}{R\+W\+Lock\+::write\+Unlock()} called while not holding the write lock, object deleted in another thread, etc \\
\hline
\end{DoxyExceptions}
