D2 weak references

grauzone none at example.net
Tue Apr 21 21:45:22 PDT 2009


> Is it possible for druntime to expose an option as to whether or not the 
> sweep phase / finalizers should run while all threads are suspended?

But then you can only do boring stuff in the finalizer. Calling any C or 
library function must be avoided, because it can lead to deadlocks. At 
the same time, your code is called at arbitrary times, and anything you 
do will cause race conditions by default. It's like a UNIX signal 
handler: programming in it sucks so much.

Maybe the finalizer register function could take two callbacks: one 
called before threads are resumed, and one after threads are resumed. 
You could use the first callback to zero out the weak reference, while 
the second takes care of advanced functionality, like notifying someone 
that the reference has been collected.



More information about the Digitalmars-d mailing list