2009/10/23 Schwab,Wilhelm K <[email protected]>:
> Sig,
>
> One can always construct examples in which protecting the entire loop is the 
> better option.  That's not the scenario of interest.  Just as shared queues 
> are useful, shared sets and dictionaries have value for sporadic access 
> scenarios.  Doing it your way, everyone writes their own incompletely 
> protected (read buggy/dangerous) ad-hoc implementations of these common 
> collections.
>
> I favor having solid implementations that are complete and as correct as we 
> can get them, leaving people to optimize as you suggest when it makes sense 
> to do so.
>
> Bill
>
>
Here is what you need. And you have a thread-safe collections for
free.. and not only collections, you can use it for anything you want
:)


'From Squeak3.10.2 of ''5 June 2008'' [latest update: #7179] on 23
October 2009 at 3:41:44 am'!
Object subclass: #SharedResource
        instanceVariableNames: 'resource lock'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'CorruptVM-tests'!

!SharedResource methodsFor: 'as yet unclassified' stamp: 'sig 10/23/2009 03:36'!
doesNotUnderstand: aMessage
        | result |
        lock critical: [
                result := aMessage sentTo: resource
        ].

        ^ result! !

!SharedResource methodsFor: 'as yet unclassified' stamp: 'sig 10/23/2009 03:36'!
initialize
        lock := Semaphore forMutualExclusion ! !

!SharedResource methodsFor: 'as yet unclassified' stamp: 'sig 10/23/2009 03:35'!
resource: anObject
        resource := anObject! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

SharedResource class
        instanceVariableNames: ''!

!SharedResource class methodsFor: 'as yet unclassified' stamp: 'sig
10/23/2009 03:37'!
on: anObject
        ^ self new resource: anObject! !


------------

i know its a brain-dead way.. but do you really think that you can get
something better with implementing collections
without ending up with fact, that almost every method will require a
semaphore to protect from race condition? :)

-- 
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to