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>
index | next in thread | raw e-mail
[-- Attachment #1 --]
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: ˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙GC
thread id 134531072, &arg: 0x8055020, arg: ˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙GC
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
$
[-- Attachment #2 --]
#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) {
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 = 0;
pthread_t thread[MAX_THREADS];
DIR *directory;
struct dirent* entry;
// on ouvre le répertoire en argument
directory = opendir(argv[1]);
for (i = 0; (entry = readdir(directory) ) != NULL; i++) {
if (i+1 <= MAX_THREADS) {
// création du thread
if (pthread_create(& (thread[i]), NULL, statfile, entry->d_name) != 0)
warn("main");
printf("Dir entry: %p, %s\n", entry->d_name, entry->d_name);
}
} // prochain fichier du répertoire
threadCnt = i;
(void)closedir(directory);
// on attend que les enfants se terminent
for (i = 0; i < threadCnt; i++) {
pthread_join(thread[i], NULL);
}
return 0;
} // fin
[-- Attachment #3 --]
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
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?14494.21789.847287.358066>
