|
563 | 563 | then unlocks them in the \emph{post-fork} handler (both for the parent and the |
564 | 564 | child), you will avoid such deadlocks. When locking mutexes in the |
565 | 565 | pre-fork handler, other threads are still running so the mutexes held by them |
566 | | -can be released (usually each thread exits a crititcal section in a short time |
| 566 | +can be released (usually each thread exits a critical section in a short time |
567 | 567 | in well written code). Example: \example{pthreads/atfork.c}. For more on this |
568 | 568 | topic, see [Butenhof]. |
569 | 569 | \item See page \pageref{MUTEXES} on why mutexes locked in other threads on |
|
710 | 710 | \item Mutex = \emph{mutual exclusion} |
711 | 711 | \item Special form of Dijkstra semaphores -- the difference between mutexes and |
712 | 712 | binary semaphores is that \emsl{mutex has an owner and locked mutex must be |
713 | | -unlocked only by the thread that acquied it.} This is not the case with |
714 | | -semephores. In order to check whether given mutex was locked by different thread |
| 713 | +unlocked only by the thread that acquired it.} This is not the case with |
| 714 | +semaphores. In order to check whether given mutex was locked by different thread |
715 | 715 | when acquiring it, it is necessary to test return value of |
716 | 716 | \texttt{p\-thread\_mutex\_lock}, and also have the lock checking set, see below. |
717 | 717 | \item Mutexes are meant to be held for short time only. They are used for |
|
766 | 766 | % \cline{2-4} |
767 | 767 | \end{tabular}} |
768 | 768 | \item Static mutex initialization using before mentioned macro will set default |
769 | | -attributes. It is possbile to use initializer function also for statically |
| 769 | +attributes. It is possible to use initializer function also for statically |
770 | 770 | allocated mutex. If a mutex is dynamically allocated, it is always necessary to |
771 | 771 | use \texttt{pthread\_mutex\_init}, even if the default attributes are desired or |
772 | 772 | not. |
|
819 | 819 | \item Locking a mutex that is being held by another thread is not correct. |
820 | 820 | Sometimes a (self)deadlock can ensue, see the previous page. If you need to |
821 | 821 | unlock a mutex locked by different thread, use binary semaphores instead. |
822 | | -\item When creating a program where effectivity is paramount, it is necessary to |
| 822 | +\item When creating a program where efficiency is paramount, it is necessary to |
823 | 823 | think about how many mutexes will be needed and how exactly will be used. |
824 | 824 | Even a library that was not written with threads in mind can be converted to be |
825 | 825 | thread-safe (see page \pageref{THREADSAFE}) by inserting arbitrary function from |
|
873 | 873 | 7}''. Conditional variable can be in fact compared to a flag of certain color; |
874 | 874 | if it is lifted up, it means that the threads waiting for the flag to be waved |
875 | 875 | are informed (= woken up) and can use this information according its own |
876 | | -judgement. Some threads can wait for \texttt{n} to be bigger than 7, the other |
| 876 | +judgment. Some threads can wait for \texttt{n} to be bigger than 7, the other |
877 | 877 | can be waiting solely for \texttt{n} to change anyhow. It is only up to the |
878 | 878 | programmer, if for concrete situation uses just one condition variable or |
879 | 879 | for all situations. For the second situation, the threads waiting on |
|
967 | 967 | \item one conditional variable can be used to announce multiple situations |
968 | 968 | at once -- e.g. when inserting or removing an item to/from a queue. |
969 | 969 | Because of this, it is necessary to test the condition the thread is waiting |
970 | | -for. Another consequence of this is that it is neccessary to use broadcast |
| 970 | +for. Another consequence of this is that it is necessary to use broadcast |
971 | 971 | in such situation. Let's assume that both readers and writers are waiting for |
972 | 972 | condition ``state of queue has changed''. If only single wakeup event is made |
973 | 973 | after item insertion to the queue, then another writer can be woken up, |
|
1308 | 1308 | \sltitle{Thread-safe versus reentrant} |
1309 | 1309 |
|
1310 | 1310 | \begin{itemize} |
1311 | | -\item \emph{thead-safe} means that the function can be called from multiple |
| 1311 | +\item \emph{thread-safe} means that the function can be called from multiple |
1312 | 1312 | threads in parallel without destructive consequences |
1313 | 1313 | \begin{itemize} |
1314 | 1314 | \item a function which was not designed to be thread-safe can be |
|
1390 | 1390 | \item Solaris |
1391 | 1391 | \begin{itemize} |
1392 | 1392 | \item \funnm{pthread\_cond\_reltimedwait\_np}\texttt{(\dots)} |
1393 | | -\item[$\rightarrow$] like timedwait, however the timeout is relative |
| 1393 | +\item[$\rightarrow$] like \texttt{timedwait}, however the timeout is relative |
1394 | 1394 | \end{itemize} |
1395 | 1395 |
|
1396 | 1396 | \item OpenBSD |
|
0 commit comments