Garbage Collection Issue
Steven Schveighoffer
schveiguy at gmail.com
Mon Jun 1 12:37:05 UTC 2020
On 6/1/20 6:51 AM, IGotD- wrote:
> On Sunday, 31 May 2020 at 16:57:06 UTC, Steven Schveighoffer wrote:
>>
>> I can't imagine much of druntime working at all without TLS. Indeed,
>> it is a requirement these days.
>>
>> I believe that's where these roots are being stored.
>>
>
> I would really like if druntime could remove its TLS variables as much
> as possible. TLS is really a complicated solution underneath and
> druntime makes it even more complicated. It requires a hook in thread
> creation since the raw TLS specification only applies simple variables
> that can be initialized using memcpy/memset. Any thread that is created
> outside the druntime will fail if D supports "complex" TLS variables.
D can use non-D created threads, but they will not be scanned by the GC,
or run thread static constructors or destructors.
>
> TLS variables are also slower that normal variables since it often
> requires a system call in order to obtain the variable.
I was under the impression that TLS works by altering a global pointer
during the context switch. I didn't think accessing a variable involved
a system call.
For sure they are slower than "normal" variables, but how much slower?
I'm not sure.
>
> druntime should use stack variables much it can and/or shared variables.
druntime does not needlessly use TLS as far as I know. If you find a
case that can be switched please file a bug report.
>
> If you ever encounter a TLS variable which is global variable in D, try
> to see if you can solve it with a stack or shared variable.
This can only take you so far, when the language uses TLS by default.
The GC has to support scanning TLS and so it uses TLS to track
thread-specific data.
What it sounds like to me is that the OP implemented a "get it to
compile" solution for TLS, and this is not working for him.
There is no removing TLS, because the language uses it directly for
global variables, and many guarantees are enabled by it.
For instance the array append runtime uses a lock-free TLS cache to
ensure speedy appending. Without TLS, the global lock would be needed
for every append.
-Steve
More information about the Digitalmars-d-learn
mailing list