[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: strage cthread behavior
From: |
Manu Valderrama |
Subject: |
Re: strage cthread behavior |
Date: |
Sat, 29 Jun 2002 23:56:57 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 |
Hi Matej ! I have a little experience in cthreads, but not much. I
will try
to respond so good as I 'm able to, but understand that my experience is
lacking, and then I could give an incorrect awnser.
>I started playing with hurd. I am trying
>to gain some experience with `cthread'
>library now.
Maybe a good introductory tutorial is in :
http://www.fprintf.net/hurd/cth-hello.tar.bz2
there are also some sample programs inside.
Let's see a little about your program :
>void child_fnc( int i )
>{
> printf( "slave:0\n" );
>}
I think that the root of your problems are in these printf's and like;
you are supposing
that this printf is thread-safe, but the reason of the strange behavior
you get
is that probably these printf's are thread-unsafe ( and explanation
about the thread-safety
issue is inside cth-hello.tar.bz2 ).
IMHO a possible solution, that has correctly worked for me,
is to declare a mutex like this :
mutex_t unsafe_libs;
and protect with this mutex _all_ the printf's inside your program.
The only things you need to learn is the use of mutex_alloc, mutex_lock,
mutex_unlock and mutex_free. Read about their use, for example, in the
"Mach 3 Server Writer's Guide" ( look here for it :
http://www-2.cs.cmu.edu/afs/cs/project/mach/public/www/doc/documents_top.html
). Is easy, but anyway good luck.
>`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
I'm not fully sure, but I think that these two examples work
because in Linux most libraries are thread-safe ( something is
also said in the document I have mentioned before ).
Bye Matej!
( sorry for sending this message twice;
but the crappy smtp server of hotpop sends mi message
about 10 hours later I send my mail; finally I managed
to change the smtp server )
Re: strage cthread behavior, Manu Valderrama, 2002/06/30