[openbeos] Re: Waiting and waiting
- From: argent@xxxxxxxxxxxxxxxxxx
- To: openbeos@xxxxxxxxxxxxx
- Date: Tue, 10 Dec 2002 11:12:31 -0500
on Tue, Dec 10, 2002 at 03:45:43PM +0100, Fran?ois Revol was heard to have
remarked:
> En r?ponse ? Michael Phipps <mphipps1@xxxxxxxxxxxxxxxx>:
> > Would you think that this would apply to things like strtok?
> > That would be a good example for testing...
>
> This one is the perfect example of self-contained function (not dealing with
> IO or anything) that doesn't need to be taken care of. Except of course if
> you implement it using global variables, but this would be very dumb :^)
Not really. Remember that threads in the same process share the same
address space, and the same copy of the standard library. If I
understand correctly, the following sequence is legal:
thread1 thread2
strtok("two words", " ")
strtok(NULL, " ")
(In this case, thread1 would get "two", and thread2 would get "words",
except that (at least on OpenBSD), strtok modifies the first argument,
and you could have bad things happen if it is in the initialized data segment.)
> as long as it uses local variables *only* it can be considered as
> intrinsically thread-safe, as each instance is fully located on the stack of
> the calling thread.
Yes. But strtok() is not one of those functions. By it's definition,
it sets a global state, then uses that. strtok_r() *is* re-entrant,
and it's trivial to make strtok_r() thread-safe.
> On the opposite every function that deals with something that belongs to a
> whole team (memory, files, ...) must use locking (malloc(), fread, ...)
(Mostly) agreed. There's also the possibility to use atomic
operations. ;-)
--
Evan Knop <argent@xxxxxxxxxxx> http://lore.dartmouth.edu/~argent/
"Out of register space (ugh)"
- vi
- References:
- [openbeos] Re: Waiting and waiting
- From: Michael Phipps
- [openbeos] Re: Waiting and waiting
- From: François Revol
Other related posts:
- » [openbeos] Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- » [openbeos] Re: Waiting and waiting
- [openbeos] Re: Waiting and waiting
- From: Michael Phipps
- [openbeos] Re: Waiting and waiting
- From: François Revol