% % This file was automatically produced at Feb 27 2003, 22:51:56 by % c2latex -c hello512.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: hello512.c\mbox{}\\ $\ast$ DESCRIPTION:\mbox{}\\ $\ast$ A "hello world" Pthreads program which creates a large number of \mbox{}\\ $\ast$ threads per AIX process. A sleep() call is used to insure that all\mbox{}\\ $\ast$ threads are in existence at the same time. Each Hello thread does some\mbox{}\\ $\ast$ work to demonstrate how the AIX scheduler behavior affects thread \mbox{}\\ $\ast$ completion order.\mbox{}\\ $\ast$\mbox{}\\ $\ast$ SOURCE: 9/98 Blaise Barney\mbox{}\\ $\ast$ LAST REVISED: 9/20/98 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 512\mbox{}\\ \mbox{}\\ {\bf void} $\ast$Hello({\bf void} $\ast$threadid)\mbox{}\\ \{\mbox{}\\ \hspace*{3\indentation}{\bf int} i;\mbox{}\\ \hspace*{3\indentation}{\bf double} result=0.0;\mbox{}\\ \hspace*{3\indentation}sleep(3);\mbox{}\\ \hspace*{3\indentation}{\bf for} (i=0; i$<$1000; i++)\mbox{}\\ \hspace*{3\indentation}\{\mbox{}\\ \hspace*{5\indentation}result = result + ({\bf double})random(); \mbox{}\\ \hspace*{3\indentation}\}\mbox{}\\ \hspace*{3\indentation}printf({\tt"\%d: Hello World!$\backslash$n"}, threadid);\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}{\bf int} rc, t;\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}printf({\tt"Code \%d$=$ \%s$\backslash$n"},rc,strerror(rc));\mbox{}\\ \hspace*{9\indentation}exit($-$1);\mbox{}\\ \hspace*{6\indentation}\}\mbox{}\\ \hspace*{3\indentation}\}\mbox{}\\ \hspace*{3\indentation}printf({\tt"main(): Created \%d threads.$\backslash$n"}, t);\mbox{}\\ \hspace*{3\indentation}pthread\_exit(NULL);\mbox{}\\ \}\mbox{}\\ \end{flushleft} \end{document}