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.