Gang,

> On June 25, 2001 Richard Basham wrote:

> In this piece of code you are using attr to hold the 
> attributes of the thread.  That is fine.  However, below...

> you are using the same attr variable for the second thread.  

        A browse of the source of pthread_create shows that this is not a
problem.  Unless the RTL guys say otherwise, we should feel free to do this
at will.

> I am not an expert but I believe that since the calls to the 
> pthread routines require &attr that they are modifying its 
> values.  This could include the address of the thread to get 
> executed.  Since you created the thread for the adc first it 
> executes once.  Then you create the thread for the servo loop 
> and it modifies the attr structure to look at the servo loop 
> and it continues to run.

        Nothing is stored in the attr structure other than input attributes
for the new thread.  Assuming they are the same for the two threads (or you
change those that change), there will be no problem using the same attr
structure.

> Hope this helps, and hope it doesn't hurt.

        As long as he remembers to do a pthread_attr_init on the new attr
structure, I do not see how it could possibly hurt.

        There is one potential case in which reusing an attr structure could
be problematic (spectacularly so, in fact).  The attr structure contains a
space for a stack address.  pthread_attr_init initializes this to 0s and
then pthread_create finds a place for the stack.  If, for some reason, a
user chose to define the stack address, then reusing the attr structure
would result in two threads using the same stack.  That won't work for very
long. :-)

        Of course, all of this is my analysis of the situation.  I do not
work for FSM Labs, so take it with the appropriate grain of salt.  Perhaps
Michael or Victor will bless the above?

Regards,

Steve Cohen

----- End of forwarded message from [EMAIL PROTECTED] -----
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/

Reply via email to