🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.linux.development.apps
5 messages
5 total messages Started by Vi Nham Wed, 01 Oct 1997 00:00
[POSIX Thread] Cannot Compile
#43
Author: Vi Nham
Date: Wed, 01 Oct 1997 00:00
102 lines
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)
Re: [POSIX Thread] Cannot Compile
#44
Author: Laurent Michel
Date: Wed, 01 Oct 1997 00:00
20 lines
1253 bytes
You need to install the thread library. Usually it is not bundled with
Linux distribution. Here are some pointers:

http://pauillac.inria.fr/~xleroy/linuxthreads/

http://linas.org/linux/threads-faq.html

http://centaurus.cs.umass.edu/~wagner/threads_html/tutorial.html


WRT. the compilers flag, If I remember  correctly, you need
-D_REENTRANT. Besides that its pretty much peachy. Just make sure you
use MT-safe version of your libraries (don't expect the standard X11R6
to behave normally if it wasn't compiled for MT usage).


-- 

	- Laurent
Re: [POSIX Thread] Cannot Compile
#45
Author: Mark A. Crampton
Date: Thu, 02 Oct 1997 00:00
19 lines
1139 bytes
Vi Nham wrote:
> 
> 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 understand that the "MIT threads" are different than pthreads.

> I could not find any library file for linking.
> 
> Here is an example I try to compile.....
>
Re: [POSIX Thread] Cannot Compile
#46
Author: Mike Holland
Date: Fri, 03 Oct 1997 00:00
24 lines
1407 bytes
Vi Nham wrote:
> 
> 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???

Are those...! Could it be... BACKslashes? A mark of evil.  BEGONE!!

BTW, how about posting the error messages?
Do you want kernel or user threads?

-- 
Mike Holland <mike@golden.wattle.id.au>            Perth, Australia.
Never attribute to poor spelling, that which can be explained by bad
typing.

PGP ID 8B3D0765. FP: 30 07 BF 6C 9B 45 E8 C8  EA 30 4F 01 DC A2 91 88
Re: [POSIX Thread] Cannot Compile
#47
Author: Steve Murray
Date: Sat, 04 Oct 1997 00:00
56 lines
2192 bytes
Vi Nham wrote:
> 
> 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>

[source removed for brevity]

>  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)

You've probably not got libpthreads installed - might I suggest that you
have a look at the Linux Threads Home Page - it's got information that
will
sort you out !

http://linas.org/linux/threads-faq.html

I think one of the better POSIX compliant threads packages is
LinuxThreads
by Xavier Leroy - it's a kernel-space implementation.

Cheers,
Steve
-- 
Steve Murray
Computer Systems Engineering Group
Faculty of Engineering
The University of Technology, Sydney

email: stevem@eng.uts.edu.au
www:   http://www.ee.uts.edu.au/~stevem/
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads