Linux PARISC architecture development
 help / color / mirror / Atom feed
* [parisc-linux] glibc pthreads actual threads?
@ 2003-05-19 16:27 Joel Soete
  2003-05-19 16:32 ` Matthew Wilcox
  2003-05-19 16:32 ` Matthew Wilcox
  0 siblings, 2 replies; 8+ messages in thread
From: Joel Soete @ 2003-05-19 16:27 UTC (permalink / raw)
  To: parisc-linux; +Cc: debian-hppa

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [parisc-linux] glibc pthreads actual threads?
@ 2003-05-19 16:27 Joel Soete
  0 siblings, 0 replies; 8+ messages in thread
From: Joel Soete @ 2003-05-19 16:27 UTC (permalink / raw)
  To: parisc-linux; +Cc: debian-hppa

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [parisc-linux] glibc pthreads actual threads?
  2003-05-19 16:27 [parisc-linux] glibc pthreads actual threads? Joel Soete
  2003-05-19 16:32 ` Matthew Wilcox
@ 2003-05-19 16:32 ` Matthew Wilcox
  2003-05-19 17:01   ` Joel Soete
                     ` (3 more replies)
  1 sibling, 4 replies; 8+ messages in thread
From: Matthew Wilcox @ 2003-05-19 16:32 UTC (permalink / raw)
  To: Joel Soete; +Cc: parisc-linux, debian-hppa

On Mon, May 19, 2003 at 06:27:41PM +0200, Joel Soete wrote:
> 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?

it's a limit of your understanding ;-)  POSIX specifies both behaviours
are legitimate.

-- 
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [parisc-linux] glibc pthreads actual threads?
  2003-05-19 16:27 [parisc-linux] glibc pthreads actual threads? Joel Soete
@ 2003-05-19 16:32 ` Matthew Wilcox
  2003-05-19 16:32 ` Matthew Wilcox
  1 sibling, 0 replies; 8+ messages in thread
From: Matthew Wilcox @ 2003-05-19 16:32 UTC (permalink / raw)
  To: Joel Soete; +Cc: parisc-linux, debian-hppa

On Mon, May 19, 2003 at 06:27:41PM +0200, Joel Soete wrote:
> 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?

it's a limit of your understanding ;-)  POSIX specifies both behaviours
are legitimate.

-- 
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [parisc-linux] glibc pthreads actual threads?
  2003-05-19 16:32 ` 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
  3 siblings, 0 replies; 8+ messages in thread
From: Joel Soete @ 2003-05-19 17:01 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: parisc-linux, debian-hppa

>
>it's a limit of your understanding ;-)

Normal: as mentioned I just started to learn...

>  POSIX specifies both behaviours
>are legitimate.
>
Thanks for those clarification,
    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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [parisc-linux] glibc pthreads actual threads?
  2003-05-19 16:32 ` Matthew Wilcox
@ 2003-05-19 17:01   ` Joel Soete
  2003-05-19 17:01   ` Joel Soete
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Joel Soete @ 2003-05-19 17:01 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: parisc-linux, debian-hppa

>
>it's a limit of your understanding ;-)

Normal: as mentioned I just started to learn...

>  POSIX specifies both behaviours
>are legitimate.
>
Thanks for those clarification,
    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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [parisc-linux] glibc pthreads actual threads?
  2003-05-19 16:32 ` 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
  3 siblings, 0 replies; 8+ messages in thread
From: Joel Soete @ 2003-05-22  9:52 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: parisc-linux, debian-hppa

>On Mon, May 19, 2003 at 06:27:41PM +0200, Joel Soete wrote:
>> 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?
>
>it's a limit of your understanding ;-)  POSIX specifies both behaviours
>are legitimate.
>
Just for remind and for those who also have this kind of philophical pb :-)).
In fact following test, an ardent discuss born here between high level system
engineer and one of them help me to find this interesting link:
<http://www.onlamp.com/pub/a/onlamp/2002/11/07/linux_threads.html>

    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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [parisc-linux] glibc pthreads actual threads?
  2003-05-19 16:32 ` Matthew Wilcox
                     ` (2 preceding siblings ...)
  2003-05-22  9:52   ` Joel Soete
@ 2003-05-22  9:52   ` Joel Soete
  3 siblings, 0 replies; 8+ messages in thread
From: Joel Soete @ 2003-05-22  9:52 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: parisc-linux, debian-hppa

>On Mon, May 19, 2003 at 06:27:41PM +0200, Joel Soete wrote:
>> 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?
>
>it's a limit of your understanding ;-)  POSIX specifies both behaviours
>are legitimate.
>
Just for remind and for those who also have this kind of philophical pb :-)).
In fact following test, an ardent discuss born here between high level system
engineer and one of them help me to find this interesting link:
<http://www.onlamp.com/pub/a/onlamp/2002/11/07/linux_threads.html>

    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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-05-22  9:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-19 16:27 [parisc-linux] glibc pthreads actual threads? Joel Soete
2003-05-19 16:32 ` Matthew Wilcox
2003-05-19 16:32 ` 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
  -- strict thread matches above, loose matches on Subject: below --
2003-05-19 16:27 Joel Soete

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox