Sig, You appear to be assuming that all such access is in (big) loops. That's not always the case; sometimes, a little #at:ifAbsentPut: here or there can conflict in ugly ways, and something that gets the blocking right is non-trivial and very useful.
Bill -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Igor Stasenko Sent: Thursday, October 22, 2009 7:38 PM To: [email protected] Subject: Re: [Pharo-project] Thread-safe collections 2009/10/23 Michael van der Gulik <[email protected]>: > > > On Fri, Oct 23, 2009 at 11:23 AM, Igor Stasenko <[email protected]> wrote: >> >> 2009/10/23 Schwab,Wilhelm K <[email protected]>: >> > Hello all, >> > >> > I just looked around for thread-safe collections, and found nothing >> > that looks like a shared dictionary. The squeak-dev archives >> > contain the obligatory newbie posts (wanting all collections to be >> > thread safe) and the expected replies, some of which are overly dismissive >> > of the idea. >> > Something that protects things like #at:ifAbsentPut: and friends >> > is _really_ useful. Am I missing an existing implementation? >> > >> >> Imo, there's only one shared collection which is useful - shared >> queue. :) If you need more kinds of thread-safe collections, it >> probably indicating that the concurrent code (or model) which you >> designed is in pretty bad shape. >> >> Just compare two following snippets: >> >> 1 to: 100 do: [:i | collection threadSafeAt: i put: something]. >> >> and: >> >> semaphore critical: [ 1 to: 100 do: [:i | collection at: i put: >> something] ]. >> >> What you think, which one is better? >> > > A thread-safe collection package could have non-blocking > implementations of most methods. Writing an object reference into an > array should be an atomic operation and I assume most collections use Arrays > for their implementation. > well, #basicAt:put: using a primitive, so its already atomic operation, given than VM doesn't running the code in multiple native threads. So, there is no point in changing something for Arrays, and therefore no point to invent a non-blocking.. its already meets our demands. Lets take a look at collections which doing something more sophisticated at #at:put:, like OrderedCollection or Dictionary. What kind of non-blocking we can introduce here? Dictionary may need to rehash the array due to growth.. OrderedCollection may also need to grow its storage (if you using #add: ) and such operations is far from being atomic. So, what kind of non-blocking you can invent here? The only choice is to use blocking, and hence we are getting back to example above.. what is more efficient: 1 to: 100 do: [:i | collection threadSafeAt: i put: something]. or: semaphore critical: [ 1 to: 100 do: [:i | collection at: i put: something] ]. > Gulik. > > -- > http://gulik.pbwiki.com/ > > _______________________________________________ > Pharo-project mailing list > [email protected] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project > -- Best regards, Igor Stasenko AKA sig. _______________________________________________ Pharo-project mailing list [email protected] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project _______________________________________________ Pharo-project mailing list [email protected] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
