Article View: comp.os.linux.development.apps
Article #43[POSIX Thread] Cannot Compile
From: Vi Nham
Date: Wed, 01 Oct 1997 00:00
Date: Wed, 01 Oct 1997 00:00
102 lines
2792 bytes
2792 bytes
Hi everyone,
I have trouble compile a Posix Thread example on Linux (kernel 2.0.0).
I believe my working environment is not setup correctly, can anyone give
some direction please?
I found pthread.h in \usr\include directory.
This pthread is somehow linked to \usr\include\mit\pthread???
I could not find any library file for linking.
Here is an example I try to compile.....
======================================================
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include <varargs.h> /* for errexit */
#include <sys/types.h>
#include <time.h> /* for time */
#include <math.h>
void *print_name(void *args)
{
double div=10;
int i;
for(i=0;i<1000;i++)
{
div = div*M_PI;
div = div/(M_PI*i);
}
pthread_exit;
}
int errexit(format,va_alist)
char *format;
va_dcl
{
va_list args;
va_start(args);
_doprnt(format,args,stderr);
va_end(args);
exit(1);
}
/*MAIN*/
int main(argc,argv)
int argc;
char *argv[];
{
int threads;
int i;
pthread_t *tid; /* pointer to thread id array */
time_t clock=1;
double now;
if (argc < 2)
{
errexit("Usage : %s threads\n",argv[0]);
}
srand(getpid());
threads = atoi(argv[1]);
/* create the array of holders for the thread ids */
if (( tid = (pthread_t *) calloc(threads,sizeof(pthread_t))) == NULL)
errexit("Unable to calloc memory\n",threads);
now = time(&clock);
printf("%f\n",now);
for(i=0;i<threads;i++)
{
if (pthread_create((tid+i),NULL,print_name,NULL))
errexit("Could not create thread %i : %s\n",i,strerror(errno));
}
/* wait for all threads to finish */
for (i=0;i<threads;i++)
pthread_join(*(tid+i),NULL);
now = time(&clock);
printf("%f\n",now);
pthread_exit;
}
===========================================
If someone could tell me the compiler switch to use, to file to look for
or any FAQ to do with Posix thread programming in Linux environment, I
am very much appreciated.
--
Regards,
Vi Nham (vnham@socs.uts.edu.au)
Technical Details
Message-ID:
<34331A2B.7E18A2ED@socs.uts.EDU.AU>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10c696,d483269fd06e2623,start X-Google-Attributes: gid10c696,public X-Google-Thread: 102983,d483269fd06e2623,start X-Google-Attributes: gid102983,public X-Google-Thread: ffc1e,d483269fd06e2623,start X-Google-Attributes: gidffc1e,public From: Vi Nham <vnham@socs.uts.EDU.AU> Subject: [POSIX Thread] Cannot Compile Date: 1997/10/01 Message-ID: <34331A2B.7E18A2ED@socs.uts.EDU.AU> X-Deja-AN: 276993345 X-Priority: 3 (Normal) X-Complaints-To: news@socs.uts.EDU.AU X-Trace: woodstock.socs.uts.EDU.AU 875702821 14194 (None) 138.25.14.67 Organization: UTS Newsgroups: comp.os.linux.development.apps,aus.computers.linux,comp.programming.threads