\hypertarget{class_qore_1_1_thread_1_1_auto_read_lock}{}\section{Qore\+:\+:Thread\+:\+:Auto\+Read\+Lock Class Reference}
\label{class_qore_1_1_thread_1_1_auto_read_lock}\index{Qore\+::\+Thread\+::\+Auto\+Read\+Lock@{Qore\+::\+Thread\+::\+Auto\+Read\+Lock}}


A helper class for the \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} class for exception-\/safe read lock handling.  


\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{class_qore_1_1_thread_1_1_auto_read_lock_ac509ed11681dce1cf2dd2d09cc5f6650}{constructor} (\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} rwl)
\begin{DoxyCompactList}\small\item\em Creates the \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} object based on the \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} argument passed and immediately calls \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_ad8ab081b2f254129ec042d614fbb1485}{R\+W\+Lock\+::read\+Lock()} \end{DoxyCompactList}\item 
\hyperlink{class_qore_1_1_thread_1_1_auto_read_lock_a1549404caafd7bfb69b0b8db92588711}{copy} ()
\begin{DoxyCompactList}\small\item\em Throws an exception; objects of this class cannot be copied. \end{DoxyCompactList}\item 
\hyperlink{class_qore_1_1_thread_1_1_auto_read_lock_a410f4f725f6dc167882eae0ef6ebffa0}{destructor} ()
\begin{DoxyCompactList}\small\item\em Calls \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a1a32805ce5cc129d2ed2bf96b01a7d4c}{R\+W\+Lock\+::read\+Unlock()} on the saved \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} and destroys the \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} object. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
A helper class for the \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} class for exception-\/safe read lock handling. 

\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}
\hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} objects, when used along with a \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} object, allow Qore programmers to safely acquire and release a read lock, even if exceptions are thrown or return statements are executed in the block where the \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} object is created.

\hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} objects are helper objects that acquire a read lock for the lifetime of the \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} object. For this reason, it is only appropriate to assign an \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} object to a local variable, so when the local variable goes out of scope, the \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} object will be deleted and the read lock will be automatically released.

For example\+: 
\begin{DoxyCode}
our RWLock rwl();

sub check\_error(error) \{
    \textcolor{comment}{# note that the read lock is acquired in the AutoReadLock constructor, and}
    \textcolor{comment}{# the read lock will be released as soon as the block is exited below.}
    \textcolor{comment}{# (with either the throw statement or the return statement)}
    AutoReadLock arl(rwl);
    \textcolor{keywordflow}{if} (error)
        throw \textcolor{stringliteral}{"ERROR"}, \textcolor{stringliteral}{"sorry, an error happened"};

    \textcolor{keywordflow}{return} \textcolor{stringliteral}{"OK"};
\}
\end{DoxyCode}


\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_auto_read_lock_ac509ed11681dce1cf2dd2d09cc5f6650}\label{class_qore_1_1_thread_1_1_auto_read_lock_ac509ed11681dce1cf2dd2d09cc5f6650}} 
\index{Qore\+::\+Thread\+::\+Auto\+Read\+Lock@{Qore\+::\+Thread\+::\+Auto\+Read\+Lock}!constructor@{constructor}}
\index{constructor@{constructor}!Qore\+::\+Thread\+::\+Auto\+Read\+Lock@{Qore\+::\+Thread\+::\+Auto\+Read\+Lock}}
\subsubsection{\texorpdfstring{constructor()}{constructor()}}
{\footnotesize\ttfamily Qore\+::\+Thread\+::\+Auto\+Read\+Lock\+::constructor (\begin{DoxyParamCaption}\item[{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}}]{rwl }\end{DoxyParamCaption})}



Creates the \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} object based on the \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} argument passed and immediately calls \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_ad8ab081b2f254129ec042d614fbb1485}{R\+W\+Lock\+::read\+Lock()} 

Creates the \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} object based on the \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} argument passed. The \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} object immediately calls \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_ad8ab081b2f254129ec042d614fbb1485}{R\+W\+Lock\+::read\+Lock()} on the \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} object passed, and saves it so it can be released when the \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} object is destroyed.

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
AutoReadLock arl(rwlock);
\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_auto_read_lock_a1549404caafd7bfb69b0b8db92588711}\label{class_qore_1_1_thread_1_1_auto_read_lock_a1549404caafd7bfb69b0b8db92588711}} 
\index{Qore\+::\+Thread\+::\+Auto\+Read\+Lock@{Qore\+::\+Thread\+::\+Auto\+Read\+Lock}!copy@{copy}}
\index{copy@{copy}!Qore\+::\+Thread\+::\+Auto\+Read\+Lock@{Qore\+::\+Thread\+::\+Auto\+Read\+Lock}}
\subsubsection{\texorpdfstring{copy()}{copy()}}
{\footnotesize\ttfamily Qore\+::\+Thread\+::\+Auto\+Read\+Lock\+::copy (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Throws an exception; objects of this class cannot be copied. 


\begin{DoxyExceptions}{Exceptions}
{\em A\+U\+T\+O\+R\+E\+A\+D\+L\+O\+C\+K-\/\+C\+O\+P\+Y-\/\+E\+R\+R\+OR} & objects of this class cannot be copied \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_auto_read_lock_a410f4f725f6dc167882eae0ef6ebffa0}\label{class_qore_1_1_thread_1_1_auto_read_lock_a410f4f725f6dc167882eae0ef6ebffa0}} 
\index{Qore\+::\+Thread\+::\+Auto\+Read\+Lock@{Qore\+::\+Thread\+::\+Auto\+Read\+Lock}!destructor@{destructor}}
\index{destructor@{destructor}!Qore\+::\+Thread\+::\+Auto\+Read\+Lock@{Qore\+::\+Thread\+::\+Auto\+Read\+Lock}}
\subsubsection{\texorpdfstring{destructor()}{destructor()}}
{\footnotesize\ttfamily Qore\+::\+Thread\+::\+Auto\+Read\+Lock\+::destructor (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Calls \hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a1a32805ce5cc129d2ed2bf96b01a7d4c}{R\+W\+Lock\+::read\+Unlock()} on the saved \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} and destroys the \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock} object. 

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}
delete arl;
\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, \hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock} object deleted in another thread, etc \\
\hline
\end{DoxyExceptions}
