the function is not thread-safe? what does it means?

M

_mario.lat

hallo,
what does it means "the function is not thread-safe"?
thak you in advance,
Mario.
 
O

osmium

_mario.lat said:
what does it means "the function is not thread-safe"?

Think of a thread as a synonym for process. A process is not a program and
vice versa. There are things called "fork" and "join" where a second process
can be _spawned_. Ordinary simple programs, such as a student writes have
only a single thread or process, so the constraint would not be limiting or
interesting. But such programs are at the lower limit of complexity, at
least in this dimension.
 
J

Jack Klein

Think of a thread as a synonym for process.

Why? It is an incomplete and inadequate definition, and it does not
agree with the C standards's definition of "thread".

Oh, wait a minute, there is no C standard definition of "thread".

So why are you spewing incorrect, off-topic rubbish?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
T

Tor Rustad

_mario.lat said:
hallo,
what does it means "the function is not thread-safe"?


The abstract C machine discussed here, don't have concurrent threads
executing. If a function depend on shared data, it will not be thread-safe
and the final result will be unpredictable in a multi-threaded program.

Check the comp.programming.threads FAQ for details.
 
O

osmium

Jack Klein said:
Why? It is an incomplete and inadequate definition, and it does not
agree with the C standards's definition of "thread".

Oh, wait a minute, there is no C standard definition of "thread".

So why are you spewing incorrect, off-topic rubbish?

Number 1. Because it's an immoderate group and I wanted to. Is that so
hard to figure out? Or was it a rhetorical question? The OP may get more
and better help out of the link appended here, it is more complete.

Number 2. I thought the Wikipedia link he was given was remarkably
unhelpful, IIRC it started talking about threads without saying what a
thread is. I thought what I said might possibly be more helpful than
harmful. Since about 70% of the threads on this and c.l.c++ groups are
about off-topicness, do not top post, snip signatures, do not snip
attributions, signatures must be introduced by --, no more than four lines
on a signature, read the FAQ, this is off topic, and general net etiquette I
thought what I said was at least related to computers rather than a medium
for talking about computers. Do you suppse writers spend countless hours
discussing the merits of different pencils and papers? "Spew" sounds like
an unfriendly word to me so I will wish you good day.

http://en.wikipedia.org/wiki/Reentrant
 
K

Keith Thompson

osmium said:
Number 1. Because it's an immoderate group and I wanted to. Is that so
hard to figure out? Or was it a rhetorical question? The OP may get more
and better help out of the link appended here, it is more complete.

You *wanted* to spew incorrect, off-topic rubbish? I doubt that.
Number 2. I thought the Wikipedia link he was given was remarkably
unhelpful, IIRC it started talking about threads without saying what a
thread is.

In the Wikipedia article titled "Thread-safe", the first use of the
word "thread" is a link to the article on threads.
I thought what I said might possibly be more helpful than
harmful. Since about 70% of the threads on this and c.l.c++ groups are
about off-topicness, do not top post, snip signatures, do not snip
attributions, signatures must be introduced by --, no more than four lines
on a signature, read the FAQ, this is off topic, and general net etiquette I
thought what I said was at least related to computers rather than a medium
for talking about computers. Do you suppse writers spend countless hours
discussing the merits of different pencils and papers? "Spew" sounds like
an unfriendly word to me so I will wish you good day.

<OT>
In the abstract, "threads" and "processes" are very similar; they're
things that concurrently execute code. But in the real-world
situation that the OP is probably interested in, they're very
different things. In Unix-like systems, for example, processes are
created by calling fork(); threads are created by pthread_create (or
perhaps by some routine in some other thread library). A single
process can contain multiple threads, not vice versa.
</OT>

Yes, your response did have the virtue of being related to computers,
but it was off-topic, factually incorrect, and not likely to be useful
to the OP.
 
S

Stephen Sprunk

_mario.lat said:
what does it means "the function is not thread-safe"?

It means that the function is likely to behave incorrectly if you call it
from multiple <OT>threads</OT>. The canonical example is strtok().

S
 
D

Default User

osmium said:
Since about 70% of the threads on this and c.l.c++
groups are about off-topicness, do not top post, snip signatures, do
not snip attributions, signatures must be introduced by --, no more
than four lines on a signature, read the FAQ, this is off topic, and
general net etiquette


You're a liar.



Brian
 
R

Richard Tobin

what does it means "the function is not thread-safe"?
[/QUOTE]
It means that the function is likely to behave incorrectly if you call it
from multiple <OT>threads</OT>. The canonical example is strtok().

Well, strtok() is an example of a particularly bad variant, in that
it's not even safe to interleave calls to it in different threads.
But then, it's not even safe to interleave calls to it in *one*
thread: you must finish dealing with one string before starting to
tokenise another. strtok() is not merely not re-entrant: it saves
hidden state between calls.

Functions are considered not thread safe even when things only go
wrong if you call them simultaneously. For example, malloc() might go
wrong if two calls to it simultaneously tried to update internal data
structures. In practice, implementations that provide multi-threading
also provide thread-safe implementations of most of the standard
library functions.

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top