[Seaside] Serving files

mmille10 at comcast.net mmille10 at comcast.net
Sat Oct 14 05:28:32 UTC 2006

-------------- Original message -------------- 
From: Jason Johnson <jbjohns at libsource.com> 

> David Shaffer wrote: 
> > tim Rowledge wrote: 
> >> 
> >> On 11-Oct-06, at 5:10 AM, David Shaffer wrote: 
> >> 
> >> Assuming I understand 'tread safe' in same way that you mean it, that 
> >> isn't strictly correct. The problem is that the squeak model use 
> >> separate positioning and read/writing calls. Thus is is quite 
> >> possible (been there....) to have two processes referring to the same 
> >> file and get 
> >> procA -> position: a 
> >> procB -> position: b 
> >> procA -> read from position (which I thought was a!) 
> >> boom. 
> >> 
> > I thought my meaning was the obvious one but now that I hear yours I'd 
> > agree that I was wrong. So...(let's hope the second try is a charm) 
> > 
> > Just a point of clarification: file I/O on a single Stream is not 
> > thread safe 
> I know of no languages that are. If two processes are sharing the same 
> data structure, then that will always have race conditions, unless every 
> access is blocked by a Mutex (which, of course, you don't want). 

Agreed. It sounds similar to a classic readers-writers problem, where you have multiple threads sharing a memory space, but this is with a file. In effect, it sounds like when a process reads from a file it also writes a new file position to the file I/O process, in effect "changing the buffer" for other processes that also want to read from it. I must admit I'm a total newbie to Squeak (I'll be brushing up on it soon), but from both of your descriptions it would appear that the only way to, in effect, make it thread safe would be to use mutexes, as Jason said, short of changing the VM, which has been mentioned earlier.

An idea might be to have a "thread file handler" architecture, that each thread in Squeak could use. Perhaps this could be written in Smalltalk. It would act as an intermediary between the thread and the file I/O process. It's whole job would be to handle file input, keep track of each thread's position in the file, and implement the mutex action. To make it an effective tool one would have to implement "time-sharing" of the input--limit a thread's bandwidth in terms of bytes read over a period of time. So each thread would get some file input time, rather than one thread hogging the file until it's read all the way through it.

A possible workaround to the problem discussed earlier would be to have a master copy of the file, and any time a thread needed it, it would generate a unique ID, make a copy of the original to a filename whose name is that ID, and then read from the copy, rather than the original, and delete the copy when it was done.

I assume this just has to do with multiple processes reading from the same file, not multiple processes trying to read from different files, correct?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20061014/12bf8a07/attachment.htm

More information about the Seaside mailing list