tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] make tcc reentrant


From: grischka
Subject: Re: [Tinycc-devel] make tcc reentrant
Date: Fri, 06 Dec 2019 22:34:05 +0100
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

Michael Matz wrote:
Hello,

On Tue, 3 Dec 2019, Ulrich Schmidt wrote:

i try to write a lua binding for tcc. To work out propperly, the tcc lib
needs to be reentrant.

As demonstrated down-thread, that isn't correct.  It doesn't _need_ to be,
it would be an feature.  As usual with features it needs to be measured
against the downsides.  The downsides for your proposed changes are the
following at least:
1) more complicated/boiler-platy source code of TCC (a TCCState
   argument almost everywhere)
2) slower code: most of the time the indirection through a pointer
   variable (the state) in comparison to a direct access to a static
   variable doesn't matter.  But it does matter for the symbol/token
   table (and potentially for the register/evaluation stack).  I have
   measured this years ago for the token table, so this might or might not
   still be the case.

I would like to add

  3) would get in the way with "git blame" / "show origin of line" almost 
always.

  4) would break probably every patch that people might have but didn't yet 
commit.

On the other hand I could imagine a "tinier" solution where everything
is made reentrant, except compilation itself.  Such that in order to be
thread-safe one would need to put a semaphore just around the "tcc_compile()"
function.

-- grischka


So, while I can see the wish for this feature, I don't necessarily see
that tcc should be changed to accomodate.

If anything I would expect a _complete_ transition to exist, in order to
measure the impact.  The worst thing that could happen is if someone added
TCCState arguments everywhere, moved some static variables to that state,
and then leaves: none of the features of this whole excercise would be
had, but all the downsides would be there.

And yes, this is a big project.  I really think it would be better
if you simply write a wrapper for libtcc that ensures single-threadedness
and that regards TCCState as a singleton.  I think such thing would be
well-suited in the TCC sources itself.

(In a way it seems prudent for a tiny C compiler to only be usable as a
singleton)


Ciao,
Michael.

I took a look into the sources and found some comments (XXX:...) and
started with removing

the static var tcc_state. As a result allmost all lib functions needs a
1st parameter of

type TCCState*. I did this in my own local branch and tcc is still
running :).

But this is a really HUGE change. in addition most of the local vars in
tccpp, tccgen, ... needs

to be moved to TCCState. I can do that but at some points i will have
some questions and i

can only test on windows and probably on linux.

My 1st question is: Are you interested in these changes or should i do
this locally?

I would like to this together with you.


Greetings.

Ulrich.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]