grauzone Wrote: > > 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.
I've never had this kind of issue with finalizers, so I have limited appreciation for the argument. In the application I'm working on, I have no need for any functionality in this area except weak reference support. > 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. Wouldn't that implicitly require two sweep phases? In my last post, I suggested the possibiluty of a callback in the mark phase. At the moment, I'm thinking one callback at the start of collection and another callback when marking a weakly referenced object would do the trick. Any weakly referenced object not marked after the last collection is invalid