John M McIntosh johnmci@smalltalkconsulting.com wrote:
You have thread (A) that reads data from a socket, and thread (B) that writes data to the same socket. Thread (A) waits on read with Sempahore X then thread (B) happens to wait on write on Semaphore X.
Two gripes about this scenario. First, why would you have a threading situation like this in practice? Second, why stop with a reader and a writer--suppose two threads are both writing data to the same socket (probably a UDP socket)? Or, what if one thread is watching for normal closes, and another is watching for errors?
May I remind you the question is one or more semaphores? The example doesn't have to elegant, just something to show one semaphore is insufficient. In math or physics I only need one counter example to disprove a theory. I think I've give an example to show one semaphore is a problem. Since the objective is to have millions of people use Squeak I'm sure someone will think my solution is elegant.
One counterexample would be enough, but it has to be one I agree with! I argued that your example isn't something we actually need to support, and I furthermore proposed a way to solve it anyway without using more semaphores. So to convince me, you need to either refute those two arguments or find another counterexample.
Also, I had thought my UDP example was a straightforward extension of the problem and solution you've been describing. Isn't a major goal to support multithreaded access to a single socket? I wonder why one would stop at 3 threads, once they've decided that 1 isn't enough.
Regarding performance, I have a standing question against whether the 3-semaphores interface would really better performance than simply tuning the image and VM. As far as I can reconstruct the reasoning, the idea is that you won't waste time trying to write when it's reading that has become available, and vice versa. Is that about right? Well, consider that trying to write and failing can be made an extremely fast operation. Futhermore, I'd guess that most applications tend to know which operation they are waiting for at any given time. In fact, many services will naturally refuse to read any new data until they have finished spooling out their response to the last query. For such applications, which I'd tentatively guess are the majority, it is possible to guess the appropriate operation every time.
Theory aside, I eagerly await more performance data. Although, I hereby whine that people shouldn't performance tune before they have at least measured a problem! Anyway, it will be interesting to see. I betchya a 1-semaphore VM can saturate a 100MBit network, if a 3-semaphore VM can, but, we shall see.
Overall, I still think the original VM interface was fine. Of course, even if everyone agreed, we'd faced with a cost analysis of switching the Mac port from 3 semaphores -> 1, versus switching all the other ports from 1->3. Note, though, around 10-20 man-hours have already been put into updating the Unix port, and it probably isn't finished yet.
-Lex
Ok, I thought I'd ask I was doing some testing of my Carbon port today and found a problem with AsyncFilePlugin>>primitiveAsyncFileWriteStart:fPosition:fromBuffer:at:count:
It seems that it checks the buffer for type then wants to alter the buffer count.
But I think it does it wrong, hence my question to the original authors...
(interpreterProxy isBytes: buffer) ifTrue: ["covert word counts to byte counts" count _ count * 4. ...
However as you noticed the comment doesn't match the logic, if the incoming buffer is a byteArray it cheerfully sets count to count * 4, so if you write 10,000 bytes you really write 40,000 bytes.
The same applies for the read logic. Now the reason WHY the image doesn't roll over and DIE when you attempt to read 40000 into that 10000 buffer is interesting, it seems the readstart logic gets passed the unaltered size of the buffer which dictates how much to actually read into a temporary buffer. Both the actual read value 10,000 and the recalculated buffer size 40,000 is examined and the lower value used when moving the data about.
So if someone wants to fixup their logic, and perhaps think about somewhere else they might have made the same mistake when building all the plugin logic, then let me know.
If anyone is using the AsyncFile logic, then your files are 4x bigger than actually required.
-- =========================================================================== John M. McIntosh johnmci@smalltalkconsulting.com 1-800-477-2659 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com =========================================================================== Custom Macintosh programming & various Smalltalk dialects PGP Key: DSS/Diff/46FC3BE6 Fingerprint=B22F 7D67 92B7 5D52 72D7 E94A EE69 2D21 46FC 3BE6 ===========================================================================
squeak-dev@lists.squeakfoundation.org