From: "Joel Soete" <jsoe0708@tiscali.be>
To: parisc-linux@lists.parisc-linux.org
Cc: debian-hppa@lists.debian.org
Subject: [parisc-linux] glibc pthreads actual threads?
Date: Mon, 19 May 2003 18:27:41 +0200 [thread overview]
Message-ID: <3EC761CD0000080F@ocpmta2.freegates.net> (raw)
Hi all,
Sorry in advance if it is not the right place to put this question.
But I just start to learn more details about OS (A. Tanenbaum book) and
by the way try to understand a bit more about [p]threads.
I found a paper with examples (what I need much of all) and so I try by
the first one: basic_example.c (which I just change a very little for my
understanding)
/* for pthreads */
#include <pthread.h>
#include <stdio.h>
/* for getpid() */
#include <sys/types.h>
#include <unistd.h>
char * buf = "abcdefghijklmnopqrstuvwxyz";
int num_pthreads = 4;
int count = 60;
int fd = 1;
void * new_thread(void * arg)
{
int i;
pid_t PID=getpid();
for (i = 0; i < count; i++) {
fprintf(stderr, "PID: %d\n", PID);
write(fd, arg, 1); write(fd, "\n", 1);
sleep(1);
}
return(NULL);
}
main()
{
pthread_t thread;
int i;
for (i = 0; i < num_pthreads; i++) {
if (pthread_create(&thread, NULL, new_thread, (void *)(buf + i))) {
fprintf(stderr, "error creating a new thread \n");
exit(1);
}
pthread_detach(thread);
}
pthread_exit(NULL);
}
Which I compile as follow (gcc-3.3):
gcc -l pthread -o basic_example basic_example.c
That runs well (on my b2k running a 2.4.20-pa35 and libc6 2.3.1-17):
[...]
PID: 31360
a
PID: 31361
b
PID: 31362
c
PID: 31363
d
PID: 31360
a
PID: 31361
b
PID: 31362
c
PID: 31363
d
[...]
But notice a very strange behaviour:
_the pid is not the same for each thread_ ??
Having just a small sunos 5.8 with gcc-3.2.2 (but with native libpthread)
the pb does not occurs?
Is it a limit of glibc (in general or in 2.3 only?) for all linux or only
hppa?
Thanks in advance for your attention,
Joel
---------------------------------
Vous surfez avec une ligne classique ?
Economisez jusqu'à 25% avec Tiscali Complete !
Offre spéciale : première année d'abonnement offerte.
... Plus d'info sur http://complete.tiscali.be
next reply other threads:[~2003-05-19 16:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-19 16:27 Joel Soete [this message]
2003-05-19 16:32 ` [parisc-linux] glibc pthreads actual threads? Matthew Wilcox
2003-05-19 17:01 ` Joel Soete
2003-05-19 17:01 ` Joel Soete
2003-05-22 9:52 ` Joel Soete
2003-05-22 9:52 ` Joel Soete
2003-05-19 16:32 ` Matthew Wilcox
-- strict thread matches above, loose matches on Subject: below --
2003-05-19 16:27 Joel Soete
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3EC761CD0000080F@ocpmta2.freegates.net \
--to=jsoe0708@tiscali.be \
--cc=debian-hppa@lists.debian.org \
--cc=parisc-linux@lists.parisc-linux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.