Skip to content

Commit

Permalink
Fix formatting errors and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
ekcom committed Sep 30, 2024
1 parent 9368370 commit 22ffe17
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions threads/threads.tex
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ \chapter{Threads}

\section{Processes vs threads}

Creating separate processes is useful when
Creating separate processes is useful when:

\begin{itemize}
\item When more security is desired. For example, Chrome browser uses different processes for different tabs.
\item When running an existing and complete program then a new process is required, for example starting `gcc'.
\item When running an existing and complete program then a new process is required, for example starting `gcc`.
\item When you are running into synchronization primitives and each process is operating on something in the system.
\item When you have too many threads -- the kernel tries to schedule all the threads near each other which could cause more harm than good.
\item When you don't want to worry about race conditions
\item When the amount of communication is minimal enough that simple IPC needs to be used.
\end{itemize}

On the other hand, creating threads is more useful when
On the other hand, creating threads is more useful when:
\begin{itemize}
\item You want to leverage the power of a multi-core system to do one task
\item When you can't deal with the overhead of processes
Expand Down Expand Up @@ -124,11 +124,10 @@ \section{Simple Usage}

\section{Pthread Functions}

Here are some common pthread functions.
Here are some common pthread functions:

\begin{itemize}
\item \keyword{pthread\_create}.
Creates a new thread.
\item \keyword{pthread\_create} creates a new thread.
Every thread gets a new stack.
If a program calls \keyword{pthread\_create} twice, Your process will contain three stacks - one for each thread.
The first thread is created when the process start, the other two after the create.
Expand Down Expand Up @@ -185,7 +184,7 @@ \section{Pthread Functions}
\end{itemize}

There are many ways to exit threads.
Here is a non-complete list.
Here is a non-complete list:

\begin{itemize}
\item Returning from the thread function
Expand Down Expand Up @@ -442,7 +441,7 @@ \subsection{Embarrassingly Parallel Problems}
The other thing that we know is that CPUs don't have infinite cores.
To get around that, we typically keep a worker pool.
You won't see the speedup right away because of things like cache coherency and scheduling extra threads.
Over the bigger pieces of code though, you will start to see speedups.
Over the bigger pieces of code, though, you will start to see speedups.

Another embarrassingly parallel problem is parallel map.
Say we want to apply a function to an entire array, one element at a time.
Expand Down Expand Up @@ -488,8 +487,8 @@ \subsection{Advanced: Lightweight Processes?}

In the beginning of the chapter, we mentioned that threads are processes.
What do we mean by that?
You can create a thread like a process
Take a look at the example code below
You can create a thread like a process.
Take a look at the example code below.

\begin{lstlisting}[language=C]

Expand Down Expand Up @@ -543,7 +542,7 @@ \subsection{Advanced: Lightweight Processes?}

\subsection{Further Reading}

Guiding questions
Guiding questions:

\begin{itemize}
\item What is the first argument to pthread create?
Expand Down

0 comments on commit 22ffe17

Please sign in to comment.