From: <don...@is...> - 2009-02-25 23:45:07
|
Sam Steingold writes: > Don Cohen wrote: > > Since I'm only reading the database (the theory goes), I only had to > > worry about a small amount of data expected to be written inside the > > timeout and then read after, namely, the list of results. > > The solution was something like this: > > (let (results) > > (with-timeout (...) > > (... <generate> ... (push next-result results) )) > > <show results>) > the lesson, IMO, is that you should think carefully which operation > you want to time out, and put with-timeout around them, not around > the whole thing. then think carefully whether there is a way to > use select(2) (i.e., socket-status) or something similar instead of > with-timeout. In the example above, I don't think that select will help, and I don't see that the scope of the timeout can be reduced. It is exactly this operation of generating results that I want to time limit. I don't want to time limit the generation of any particular result, and even if I did, this would not help with the particular problem of aborting write operations that ought to have transactional semantics. In the particular case of the read lock, it happens that recursive read locking is treated as a noop, so it would actually solve the problem to do (withreadaccess (let (results) ...)) But I'm gradually starting to think of other data that may be written by what I think of as essentially a read operation. I wouldn't be surprised if there were analogous things going on inside the lisp implementation. As an example, there's probably some caching going on in clos, and I wouldn't be surprised if interrupting and returning from some place could leave the wrong data in this cache. I don't claim it's hard to write such code in a way that is immune to such problems, but this was probably not on the mind of the person who wrote that code originally. And clearly the programmer can't be expected to think about that data. > (IMNSHO, the above paragraph, suitably expanded and clarified, > should be in the doc string of with-timeout and in the impnotes). What do you think of my argument that this issue applies more widely than timeouts or MT ? |