Escape Analysis on reddit

Michel Fortin michel.fortin at michelf.com
Sat Nov 1 09:21:56 PDT 2008


On 2008-11-01 11:23:17 -0400, "Steven Schveighoffer" 
<schveiguy at yahoo.com> said:

> "ore-sama" wrote
>> how to mark and verify this?
>> 
>> void foo()
>> {
>>   void goo()
>>   {
>>     DoSomeJob();
>>   }
>>   JobHandle job=ThreadPool.QueueJob(&goo); //goo goes to the global state
>>   ...
>>   job.WaitForCompletion(); //but it's safe
>> }
> 
> I think your example would be impossible for the compiler to prove safe,
> even with all the code available, and all dependency graphs available.
> 
> This might be a case where you have to force the compiler to accept it.

Just create a scope ThreadPool object, accepting a scopeof(this) 
function pointer and make sure the destructor waits for completion of 
the threads.

Hum, and "goo" in this example does not use any local variable of foo, 
so there wouldn't be a need to allocate anything anyway. ;-)

That said, I think casting scope away should be allowed, but undefined 
behaviour (just as casting away immutable).

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list