[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
strage cthread behavior
From: |
Matej Kosik |
Subject: |
strage cthread behavior |
Date: |
Sat, 29 Jun 2002 12:30:16 -0100 |
Hi
I started playing with hurd. I am trying
to gain some experience with `cthread'
library now.
I wrote following trivial program:
------------------------------------
#include <stdio.h>
#include <cthreads.h>
void child_fnc( int i )
{
printf( "slave:0\n" );
}
int main()
{
cthread_t child_thread;
child_thread = cthread_fork( child_fnc, 30 );
printf( "master:0\n" );
cthread_join( child_thread );
printf( "master:1\n" );
return 0;
}
------------------------------------
if I run it as
./main
it gives me the output
master:0
slave:0
master:1
e.g. one of the things which I expected
------------------------------------
if I run the same program as
./main > output
the contents of the `./output' file
will be (surprisingly)
slave:0
master:1
I expected the contents of `./output' file
to be the same as the output of the program
printed out on terminal.
Can somebody please explain it to me?
(or send a link to some document which
explains it).
Matej Kosik
------------------------------------
NOTE (ATTACHMENT):
I attached `threads.tar.gz' file,
which holds programs concerning this problem
`threads/cthread/bug.1/main.c' contains
a program mentioned in this mail
`threads/cthread/bug.2' contains
a similar program with showing the similar
problem (it differs from `bug.1' program
in that it does not `join' the slave
but `detach' it)
`threads/pthread/bug.1' is an equivalent
program to `threads/cthread/bug.1', but
works on Linux and uses pthread instead
of cthread. I wrote it in order to see
whether it will have the bug mentioned
before --- it does not.
`threads/pthread/bug.2' is an equivalent
program to `threads/cthread/bug.2', but
works on Linux and uses pthread instead
of cthread. I wrote it in order to see
whether it will have the bug mentioned
before --- it does not.
thank you
--
http://altair.dcs.elf.stuba.sk/~kosik
threads.tar.gz
Description: GNU Zip compressed data
- strage cthread behavior,
Matej Kosik <=
Re: strage cthread behavior, Manu Valderrama, 2002/06/30