Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Feb 2000 00:16:13 -0500 (EST)
From:      Spidey <beaupran@iro.umontreal.ca>
To:        Freebsd Questions Mailing list <freebsd-questions@freebsd.org>
Subject:   PThreads
Message-ID:  <14494.21789.847287.358066@anarcat.dyndns.org>

next in thread | raw e-mail | index | archive | help

--fAdUxCTeyg
Content-Type: text/plain; charset=iso-8859-1
Content-Description: message body text
Content-Transfer-Encoding: quoted-printable

Hi!

I am currently working on a program that needs pthreads.

Is there some bugs in FBSD implementation of the pthreads? Because I'm
having serious problems here:

The following code, when executed, gives me something really weird:

$ ./test .
Dir entry: 0x8055008, .
Dir entry: 0x8055014, ..
Dir entry: 0x8055020, thread.c
Dir entry: 0x8055034, Makefile
Dir entry: 0x8055048, thread
Dir entry: 0x805505c, thread.c,v
Dir entry: 0x8055070, tp4.txt
Dir entry: 0x8055080, thread.core
Dir entry: 0x8055094, test.c
Dir entry: 0x80550a4, test
thread id 134529536, &arg: 0x8055008, arg: .
thread id 134530560, &arg: 0x8055014, arg: =FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=
=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FFGC
thread id 134531072, &arg: 0x8055020, arg: =FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=
=FF=FF=FF=FF=FF=FFGC
thread id 134531584, &arg: 0x8055034, arg: Makefile
thread id 134532096, &arg: 0x8055048, arg: thread
thread id 134532608, &arg: 0x805505c, arg: thread.c,v
thread id 135094272, &arg: 0x8055070, arg: tp4.txt
thread id 135094784, &arg: 0x8055080, arg: thread.core
thread id 135095296, &arg: 0x8055094, arg: test.c
thread id 135095808, &arg: 0x80550a4, arg: test
$

This is the source file. Compiled it with:

$ gcc test.c -Wall -pthread -DDEBUG -o test
$


--fAdUxCTeyg
Content-Type: text/plain; charset=iso-8859-1
Content-Description: test file for pthreads
Content-Disposition: inline;
	filename="test.c"
Content-Transfer-Encoding: quoted-printable

#include <err.h>
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <dirent.h>

// un plafond initial pour le nombre de threads maximum
#ifndef MAX_THREADS
#define MAX_THREADS 50
#endif

void * statfile(void *arg) {
 =20
  printf("thread id %li, &arg: %p, arg: %s\n", (long int) pthread_self(=
), arg, (char*) arg);
  return 0;

}

extern int main (int argc, char** argv) {

  int i, threadCnt =3D 0;
  pthread_t thread[MAX_THREADS];
  DIR *directory;
  struct dirent* entry;

  // on ouvre le r=E9pertoire en argument
  directory =3D opendir(argv[1]);
 =20
  for (i =3D 0; (entry =3D readdir(directory) ) !=3D NULL; i++) {

    if (i+1 <=3D MAX_THREADS) {
     =20
      // cr=E9ation du thread
      if (pthread_create(& (thread[i]), NULL, statfile, entry->d_name) =
!=3D 0)
=09warn("main");
      printf("Dir entry: %p, %s\n", entry->d_name, entry->d_name);

    }
  }  // prochain fichier du r=E9pertoire
 =20
  threadCnt =3D i;
  (void)closedir(directory);
 =20
  // on attend que les enfants se terminent
  for (i =3D 0; i < threadCnt; i++) {
    pthread_join(thread[i], NULL);
  }

  return 0;
} // fin

--fAdUxCTeyg
Content-Type: text/plain; charset=us-ascii
Content-Description: message body and .signature
Content-Transfer-Encoding: 7bit


Is there something I do not understand in pthreads or what???

Thanks a lot for any input

The AnarCat

-- 
Si l'image donne l'illusion de savoir
C'est que l'adage pretend que pour croire,
L'important ne serait que de voir

Lofofora

--fAdUxCTeyg--


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?14494.21789.847287.358066>