%
% This file was automatically produced at Feb 27 2003, 22:51:56 by
% c2latex -c hello_arg1.c
%
\documentclass[11pt,a4paper]{article}
\setlength{\textwidth}{15cm}
\setlength{\textheight}{22.5cm}
\setlength{\hoffset}{-2cm}
\setlength{\voffset}{-2cm}
\begin{document}
\expandafter\ifx\csname indentation\endcsname\relax%
\newlength{\indentation}\fi
\setlength{\indentation}{0.5em}
\begin{flushleft}
{$/\ast$\it{}$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$\mbox{}\\
$\ast$ FILE: hello\_arg1.c\mbox{}\\
$\ast$ DESCRIPTION:\mbox{}\\
$\ast$   A "hello world" Pthreads program which demonstrates one safe way\mbox{}\\
$\ast$   to pass arguments to threads during thread creation.\mbox{}\\
$\ast$\mbox{}\\
$\ast$ LAST REVISED: 09/04/02 Blaise Barney\mbox{}\\
$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast$$\ast/$}\mbox{}\\
\mbox{}\\
{\tt \#include} $<${\tt{}pthread.h}$>$\mbox{}\\
{\tt \#include} $<${\tt{}stdio.h}$>$\mbox{}\\
{\tt \#define} NUM\_THREADS	8\mbox{}\\
\mbox{}\\
{\bf char} $\ast$messages[NUM\_THREADS];\mbox{}\\
\mbox{}\\
{\bf void} $\ast$PrintHello({\bf void} $\ast$threadid)\mbox{}\\
\{\mbox{}\\
\hspace*{3\indentation}{\bf int} $\ast$id\_ptr, taskid;\mbox{}\\
\mbox{}\\
\hspace*{3\indentation}sleep(1);\mbox{}\\
\hspace*{3\indentation}id\_ptr = ({\bf int} $\ast$) threadid;\mbox{}\\
\hspace*{3\indentation}taskid = $\ast$id\_ptr;\mbox{}\\
\hspace*{3\indentation}printf({\tt"Thread \%d: \%s$\backslash$n"}, taskid, messages[taskid]);\mbox{}\\
\hspace*{3\indentation}pthread\_exit(NULL);\mbox{}\\
\}\mbox{}\\
\mbox{}\\
{\bf int} main({\bf int} argc, {\bf char} $\ast$argv[])\mbox{}\\
\{\mbox{}\\
\hspace*{3\indentation}pthread\_t threads[NUM\_THREADS];\mbox{}\\
\hspace*{3\indentation}{\bf int} $\ast$taskids[NUM\_THREADS];\mbox{}\\
\hspace*{3\indentation}{\bf int} rc, t;\mbox{}\\
\mbox{}\\
\hspace*{3\indentation}messages[0] = {\tt"English: Hello World!"};\mbox{}\\
\hspace*{3\indentation}messages[1] = {\tt"French: Bonjour, le monde!"};\mbox{}\\
\hspace*{3\indentation}messages[2] = {\tt"Spanish: Hola al mundo"};\mbox{}\\
\hspace*{3\indentation}messages[3] = {\tt"Klingon: Nuq neH!"};\mbox{}\\
\hspace*{3\indentation}messages[4] = {\tt"German: Guten Tag, Welt!"}; \mbox{}\\
\hspace*{3\indentation}messages[5] = {\tt"Russian: Zdravstvytye, mir!"};\mbox{}\\
\hspace*{3\indentation}messages[6] = {\tt"Japan: Sekai e konnichiwa!"};\mbox{}\\
\hspace*{3\indentation}messages[7] = {\tt"Latin: Orbis, te saluto!"};\mbox{}\\
\mbox{}\\
\hspace*{3\indentation}{\bf for}(t=0;t$<$NUM\_THREADS;t++)\mbox{}\\
\hspace*{3\indentation}\{\mbox{}\\
\hspace*{6\indentation}taskids[t] = ({\bf int} $\ast$) malloc({\bf sizeof}({\bf int}));\mbox{}\\
\hspace*{6\indentation}$\ast$taskids[t] = t;\mbox{}\\
\hspace*{6\indentation}printf({\tt"Creating thread \%d$\backslash$n"}, t);\mbox{}\\
\hspace*{6\indentation}rc = pthread\_create(\&threads[t], NULL, PrintHello, ({\bf void} $\ast$) taskids[t]);\mbox{}\\
\hspace*{6\indentation}{\bf if} (rc)\mbox{}\\
\hspace*{6\indentation}\{\mbox{}\\
\hspace*{9\indentation}printf({\tt"ERROR; return code from pthread\_create() is \%d$\backslash$n"}, rc);\mbox{}\\
\hspace*{9\indentation}exit($-$1);\mbox{}\\
\hspace*{6\indentation}\}\mbox{}\\
\hspace*{3\indentation}\}\mbox{}\\
\mbox{}\\
\hspace*{3\indentation}pthread\_exit(NULL);\mbox{}\\
\}\mbox{}\\
\end{flushleft}
\end{document}
