[squeak-dev] Re: [Pharo-project] #ensure: issues
leves at elte.hu
Thu Mar 4 20:57:28 UTC 2010
On Thu, 4 Mar 2010, Igor Stasenko wrote:
> 2010/3/4 Levente Uzonyi <leves at elte.hu>:
>> Here's a simple example (replace file with any external resource):
>> My process opened a file, a termination block will close it if it's
>> evaluated. If I send #terminate to the process I expect my file to be
>> closed, so I won't leak a file descriptor.
>> If the file can't be closed (aka the termination block raised an error) then
>> there's a serious problem. It doesn't really matter what happens then.
>> But I don't have to try to convince you anymore, because Andreas is about to
>> solve the issue.
> I'm not trying to convince anyone, i just wanted to show you that
> there is no good solution in that plane.
> More workarounds means more code to run (and makes things more complex, btw).
> But you will be still unsafe.You will be safe, once you stop relying
> on #ensure: in your code and use different approach.
> As for your example: use weak finalizer to close your file.
I'm about to get rid of the weak finalizer in cases where we know the
exact scope when a file is used (as with #*FileNamed:do:). There's no
point in registering and unregistering a file to the WeakRegistry if
#ensure: closes the file for us at the right time.
> This will make sure that no matter what were happen, you wont leave
> the file open. Working with external resources is a pain. But lets try
> to not poison ourselves with manual resource management, which comes
> from C world.
That's exactly what I'm about to do, keeping the resource management
automatic (from the user POV) while making it fast.
You can read my monologue about these plans here:
More information about the Squeak-dev