[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: To-be-closed variables and coroutines
- From: Dibyendu Majumdar <mobile@...>
- Date: Fri, 31 Jul 2020 19:40:34 +0100
On Fri, 31 Jul 2020 at 19:28, Egor Skriptunoff
<egor.skriptunoff@gmail.com> wrote:
>
> On Fri, Jul 31, 2020 at 8:54 PM Dibyendu Majumdar wrote:
>>
>> All I was saying is that the 'defer' statement makes less promises as
>> it makes it more explicit that some code (it can anything) will be
>> executed when the scope is exited.
>> But basically that is all that to-be-closed variables do - a promise
>> to run some code if the scope is exited. They do not promise to close
>> anything. They are not finalizers.
>> And because they are what they are, if a thread does not exit scope
>> they will never run.
>
>
> We don't need just a "scope exit event".
> The point of why to-be-closed variables exist: we need a "predictable finalizer".
> We need to guarantee that a resource will be closed as fast as possible,
> whatever happened in the code.
>
Well, the close() method will be called as soon as you exit the scope!
So it is predictable in that sense.
If the thread is never resumed, it is impossible to invoke the close
method, if you think about it.
Regards