What is multithread safety

E

E. Robert Tisdale

Randy said:
ERT, If you think that's all there is to doing it properly,
you've got even more to learn about that than you do about C.

You have confused "thread safe code" with "[multi]threaded code".
 
A

Alan Balmer

It also means avoiding *any* library function:

4 The functions in the standard library are not guaranteed to be
reentrant and may modify objects with static storage duration.
Not guaranteed by the standard (which of course doesn't guarantee
anything about multi-threaded code), but may be guaranteed by the
implementation.
 
G

goose

E. Robert Tisdale said:
Randy said:
ERT, If you think that's all there is to doing it properly,
you've got even more to learn about that than you do about C.

You have confused "thread safe code" with "[multi]threaded code".

Now I'm curious. What practical difference is there
between my single-threaded (but thread-safe) library
function and the multithreaded (and thread-safe)
calling code (other than the obvious "one calls the
other") with regard specifically to "thread-safety".


goose,
 
M

Malcolm

goose said:
Now I'm curious. What practical difference is there
between my single-threaded (but thread-safe) library
function and the multithreaded (and thread-safe)
calling code (other than the obvious "one calls the
other") with regard specifically to "thread-safety".
It is extremely easy to write a thread-safe function in C. Simply avoid
globals, static variables, pointers which may have been passed to other
threads and, of course, calling non-thread-safe suboutines.

eg

int threadsafe(int x, int y)
{
return x + y;
}

int notthreadsafe(void)
{
static int count = 0;
return count++;
}

The problem is that it seldom any use to have two threads in a program that
do not communicate with each other at all. Somehow information has to get
from thread1 to thread2, and this opens up a whole set of complications,
off-topic for this ng.
 

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

Forum statistics

Threads
474,148
Messages
2,570,838
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top