Re: GCancellable is not really cancellable?
- From: Alexander Larsson <alexl redhat com>
- To: Felipe Contreras <felipe contreras gmail com>
- Cc: gtk-devel-list <gtk-devel-list gnome org>
- Subject: Re: GCancellable is not really cancellable?
- Date: Mon, 26 Apr 2010 13:59:56 +0200
On Sun, 2010-04-25 at 22:05 +0300, Felipe Contreras wrote:
> So what am I supposed to do? ref() the object each time I do an async
> operation, and unref() it each time the operation finishes, while also
> keeping an extra field in order to find out if the object has been
> disposed?
Depends on what you mean by "object". The stream itself is automatically
refed when there is an outstanding async operation on it. If you have
further data that you need to live until the callback then you have to
ref it, or otherwise keep it alive.
> What's the point? Wouldn't it be better to truly cancel the operation?
This is how cancellation worked in gnome-vfs, and it has a few problems.
First of all, its inherently and unfixably racy in the multi-threaded
case. For instance, what if you call cancel() on a thread when the
operation just finished and we've called the callback on another cpu.
There is no way at this point to stop that emission, and its not
reasonably possible to synchronize and have the cancel fail.
Secondly, its not always possible to immediately cancel an i/o
operation, and the data passed to such an operation (for instance the
destination buffer) need to stay around until the operation is really
done, or you might be scribbling over random memory.
Third, code wise its actually not simpler, because you now get two
codepaths that free the data that was allocated for the data (free in
callback, or free after cancelling). This leads to convoluted code that
is hard to get right. With gio you can *always* assume the callback will
be called, and only once, so you can free any data there.
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Alexander Larsson Red Hat, Inc
alexl redhat com alexander larsson gmail com
He's a suave chivalrous jungle king looking for a cure to the poison coursing
through his veins. She's a tortured mutant safe cracker who can talk to
animals. They fight crime!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]