% % This file was automatically produced at Feb 27 2003, 22:51:56 by % c2latex -c hellodump.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: hellodump.c\mbox{}\\ $\ast$ DESCRIPTION:\mbox{}\\ $\ast$ A "hello world" Pthreads program that dumps core. Figure out why and\mbox{}\\ $\ast$ then fix it.\mbox{}\\ $\ast$\mbox{}\\ $\ast$ SOURCE: 9/98 Blaise Barney\mbox{}\\ $\ast$ LAST REVISED: 10/8/99 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} NTHREADS 8\mbox{}\\ {\tt \#define} ARRAY\_SIZE 16000\mbox{}\\ \mbox{}\\ {\bf void} $\ast$Hello({\bf void} $\ast$threadid)\mbox{}\\ \{\mbox{}\\ \hspace*{3\indentation}{\bf double} A[ARRAY\_SIZE];\mbox{}\\ \hspace*{3\indentation}{\bf int} i;\mbox{}\\ \hspace*{3\indentation}sleep(3);\mbox{}\\ \hspace*{3\indentation}{\bf for} (i=0; i$<$ARRAY\_SIZE; i++)\mbox{}\\ \hspace*{3\indentation}\{\mbox{}\\ \hspace*{6\indentation}A[i] = i $\ast$ 1.0;\mbox{}\\ \hspace*{3\indentation}\}\mbox{}\\ \hspace*{3\indentation}printf({\tt"\%d: Hello World! \%f$\backslash$n"}, threadid, A[ARRAY\_SIZE$-$1]);\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[NTHREADS];\mbox{}\\ \hspace*{3\indentation}size\_t stacksize;\mbox{}\\ \hspace*{3\indentation}pthread\_attr\_t attr;\mbox{}\\ \hspace*{3\indentation}{\bf int} rc, t;\mbox{}\\ \hspace*{3\indentation}pthread\_attr\_init(\&attr);\mbox{}\\ \hspace*{3\indentation}pthread\_attr\_getstacksize (\&attr, \&stacksize);\mbox{}\\ \hspace*{3\indentation}printf({\tt"Thread stack size $=$ \%d bytes (hint, hint)$\backslash$n"},stacksize);\mbox{}\\ \hspace*{3\indentation}{\bf for}(t=0;t$<$NTHREADS;t++)\{\mbox{}\\ \hspace*{6\indentation}rc = pthread\_create(\&threads[t], NULL, Hello, ({\bf void} $\ast$)t);\mbox{}\\ \hspace*{6\indentation}{\bf if} (rc)\{\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{}\\ \hspace*{3\indentation}printf({\tt"Created \%d threads.$\backslash$n"}, t);\mbox{}\\ \hspace*{3\indentation}pthread\_exit(NULL);\mbox{}\\ \}\mbox{}\\ \end{flushleft} \end{document}