Skip site navigation (1)Skip section navigation (2)
Date:      28 Aug 2002 12:06:10 -0400
From:      Joe Marcus Clarke <marcus@marcuscom.com>
To:        "Henning, Brian" <brian.henning@navitaire.com>
Cc:        "(E-mail)" <questions@FreeBSD.ORG>
Subject:   Re: pthreads compiler warnings
Message-ID:  <1030550771.329.1.camel@gyros.marcuscom.com>
In-Reply-To:  <E1846117A30764468D2192D5A48541CC03894D09@exchange.Navitaire.com>
References:   <E1846117A30764468D2192D5A48541CC03894D09@exchange.Navitaire.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 2002-08-28 at 09:40, Henning, Brian wrote:
> Hello-
> i am trying to run the following code but, when i do i get these errors. 
> Am i linking to the wrong library or doing something wrong? I read the man
> pages and it said to use libc_r
> for a threaded user program.

Don't explicitly link libc into your application.  For example, on
-stable, you should compile this like:

> cc -o xxx -pthread xxx.c

On -current:

> cc -o xxx -lc_r xxx.c

Joe

> thanks,
> brian
> 
> > gcc thread_example.c -lc_r
> /usr/lib/libc.so: WARNING!  setkey(3) not present in the system!
> /usr/lib/libc.so: warning: this program uses gets(), which is unsafe.
> /usr/lib/libc.so: warning: mktemp() possibly used unsafely; consider using
> mkstemp()
> /usr/lib/libc.so: WARNING!  des_setkey(3) not present in the system!
> /usr/lib/libc.so: WARNING!  encrypt(3) not present in the system!
> /usr/lib/libc.so: warning: tmpnam() possibly used unsafely; consider using
> mkstemp()
> /usr/lib/libc.so: warning: this program uses f_prealloc(), which is not
> recommended.
> /usr/lib/libc.so: WARNING!  des_cipher(3) not present in the system!
> /usr/lib/libc.so: warning: tempnam() possibly used unsafely; consider using
> mkstemp()
> 
> 
> 
> 
> #include <stdio.h>
> #include <pthread.h>
> 
> #define NUM_THREADS 3
> 
> void *BusyWork(void *null) {
>     int i;
>     double result = 0.0;
>     for( i = 0; i < 1000000; i++ ) {
>         result = result + (double)random();
>     }
>     printf("result = %d\n",result);
>     pthread_exit((void *) 0);
> }
> 
> int main( int argc, char *argv[] ) {
>     pthread_t thread[NUM_THREADS];
>     pthread_attr_t attr;
>     int rc, t, status;
> 
>     /* Initialize and set thread detached attribute */
>     pthread_attr_init(&attr);
>     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
> 
>     for( t = 0; t < NUM_THREADS; t++ ) {
>         printf("Creating thread %d\n", t);
>         rc = pthread_create(&thread[t], &attr, BusyWork, NULL);
>         if (rc) {
>             printf("ERROR; return code from pthread_create() is %d\n", rc);
>             exit(-1);
>         }
>     }
> 
>     /* Free attribute and wait for the other threads */
>     pthread_attr_destroy(&attr);
>     for( t = 0; t < NUM_THREADS; t++ ) {
>         rc = pthread_join(thread[t], (void **)&status);
>         if (rc) {
>             printf("ERROR; return code from pthread_join() is %d\n", rc);
>             exit(-1);
>         }
>         printf("Completed join with thread %d status= %d\n",t, status);
>     }
> 
>     pthread_exit(NULL);
>     return 0;
> }
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message
> 
-- 
PGP Key : http://www.marcuscom.com/pgp.asc


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1030550771.329.1.camel>