[Python-Dev] pre-PEP: The Safe Buffer Interface

Scott Gilbert xscottg@yahoo.com
Mon, 29 Jul 2002 23:10:16 -0700 (PDT)


--- Neil Hodgson <nhodgson@bigpond.net.au> wrote:
> Scott Gilbert:
> 
> > What happens when you've locked the buffer and passed a pointer to the
> > I/O system for an asynchronous operation, but before that operation has
> > completed, your main program wants to resize the buffer due to a user
> > generated event?
> 
>    That is up to the application or class designer. There are three
> reasonable responses I see: throw an exception, buffer the user event, or
> ignore the user event. The only thing guaranteed by providing the safe
> buffer interface is that the pointer will remain valid.
> 

The guarantee about the pointer remaining valid while the acquire_count is
positive is clear.  I'm concerned about what the other thread (the one that
wants to resize it) is going to do while the lock count is positive.

You've listed three possibilities, but lets narrow it down to the strategy
that you intend to use in Scintilla (a real use case).  I believe all three
strategies lead to something undesirable (be it polling, deadlock, a
confused user, or ???), but I don't want to exhaustively scrutinize all
possibilities until we come up with one good example that you intend to use
(it would bore you to read them, and me to type them).

So what exactly would you do in Scintilla?  (Or pick another good use case
if you prefer.)


> 
>    The buffer interface could be defined either to allow multiple
> (counted) locks or to fail further lock attempts. Counted locks would be
> applicable in more circumstances but require more implementation. I would
> prefer counted but it is not that important as a counting layer can be
> implemented over a single lock interface if needed.
> 

A single lock interface can be implemented over an object without any
locking.  Have the lockable object return simple "fixed buffer objects"
with a limited lifespan.






__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com