[Wolves] Re: Re-entrancy in C. (Peter oliver should stop being rimmed and talk to me)

bambam at opendildonics.org bambam at opendildonics.org
Sat Oct 25 18:41:21 BST 2003


On Fri, 24 Oct 2003 bambam at opendildonics.org wrote:

> How do I make my C libraries reentrant?
>
> Presumably I change the API to accept a pointer to any
> objects which should be "instance" variables - so that you
> may "re-enter" the library anywhere. Correct?

I've been thinking about this today - and I know think that
class objects are any global variable within the library
that has no need for "extra scoping", and by contrast
instance variables *could indeed* be within the library (I
previously thought that the only way to achieve this is
within the host program's address space), just referenced by
a particular token. You would of course need a function to
make more contexts - to be referenced by a token (a C++
constructor). Likewise a function would be needed to destroy
these tokens (a C++ destructor).

Is this closer to the truth?

> Also, does correct re-entrancy imply thread-safe? Surely if
> the code does not access any global variables within the
> library (are these "class" variables?) then threads using
> the library don't collide.

Ok, so "thread-safe" simply means that the threads don't
collide. I'm trying to remember my threads stuff, but
basically I've just got to make sure that memory allocation
and IO is atomic.

I'll leave it as an exercise to the host program programmer
to make sure that each thread only alters a single instance.

> Were I writing this in Java I would easily be able to
> differenciate between them from the class definition, but
> I'm not sure of how the ideas pervade C.
>
> How does static code relate to the whole thing? It seems as
> though if an object file within the shared library file
> declared a potentially global variable as static, only that
> part of the shared object can access it, but this whole idea
> still fucks up re-entrancy.

Presumably static has fuck all to do with anything - it just
has it's normal usage within the object files that make up
the library.

bambam

--
Chatting to himself since yesterday. WHERE ARE YOU PETER
OLIVER?!?!?




More information about the Wolves mailing list