June 04
On 6/4/21 2:02 AM, Andrei Alexandrescu wrote:
> On 6/2/21 12:47 PM, Steven Schveighoffer wrote:
>> On 6/2/21 6:03 AM, Andrei Alexandrescu wrote:
>>
>>> The runtime certainly has that information, so the only matter is exposing it via an API.
>>
>> Seems obvious for an API:
>>
>> scope(failure, e) // use exception e
> 
> I am hoping for an API that would allow picking the current exception from anywhere:
> 
> Throwable currentThrowable();
> 
> Returns null if none, or the current exception being thrown.
> 
> 

Doesn't that mean that throwing an exception has to stuff the exception somewhere in TLS while in flight?

I assumed it was just something stored as a local variable.

-Steve
June 04
On Friday, 4 June 2021 at 13:42:31 UTC, Steven Schveighoffer wrote:
> Doesn't that mean that throwing an exception has to stuff the exception somewhere in TLS while in flight?
>
> I assumed it was just something stored as a local variable.
>
> -Steve

Where would that local variable be, on stack? It has to be on TLS.
June 04
On 6/4/21 5:24 PM, deadalnix wrote:
> On Friday, 4 June 2021 at 13:42:31 UTC, Steven Schveighoffer wrote:
>> Doesn't that mean that throwing an exception has to stuff the exception somewhere in TLS while in flight?
>>
>> I assumed it was just something stored as a local variable.
>>
> 
> Where would that local variable be, on stack? It has to be on TLS.

Why wouldn't it be on the stack?

catch(Exception e)
{
  // is e on the stack or TLS?
}

Honestly though, stack unwinding is black magic to me. I don't know how it works, but I'm pretty sure it worked before TLS was a thing in D.

-Steve
June 04
On Fri, Jun 04, 2021 at 06:06:32PM -0400, Steven Schveighoffer via Digitalmars-d wrote: [...]
> Honestly though, stack unwinding is black magic to me. I don't know how it works, but I'm pretty sure it worked before TLS was a thing in D.

AFAIK, stack unwinding happens on the runtime stack, which is TLS (because each thread by definition has its own stack).  It's not *that* magic; it's just done at a lower level than usual language constructs.

It basically consists of starting with the current stack pointer (pointing to the top of the stack) and popping off stack frames until it finds a stack frame that registered a catch block.  At each stack frame, it runs any dtors that may be present in the frame in order to clean up any local objects that need destruction.

Where the reference to the exception object is held during this process is generally implementation detail, but I'd expect it would be either in CPU registers or else in TLS somewhere, since it wouldn't make sense for other threads to be able to stomp on an exception-in-flight (accidentally or otherwise).


T

-- 
This sentence is false.
June 09
On Friday, 4 June 2021 at 22:28:02 UTC, H. S. Teoh wrote:
> AFAIK, stack unwinding happens on the runtime stack, which is TLS (because each thread by definition has its own stack).

Reminds me of a technique used by some early java VMs: they aligned all stacks to 2MB, so to get the 'thread id', all you had to do was check sp&-2MB.

(Much faster than a load through tls segment to a ptr probably not in cache.)
Next ›   Last »
1 2