Skip to content

Commit

Permalink
Protect NewSymbols table from concurrent access when internalizing ne…
Browse files Browse the repository at this point in the history
…w symbols
  • Loading branch information
carolahp committed May 2, 2024
1 parent 5ad57b6 commit c0bc5a5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Collections-Strings/Symbol.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ Symbol class >> initialize [
{ #category : 'symbol table' }
Symbol class >> intern: aStringOrSymbol [

^ (self findInterned: aStringOrSymbol) ifNil: [
NewSymbols add: aStringOrSymbol createSymbol ]
SymbolTableSemaphore singleInstance critical: [
^ self rawIntern: aStringOrSymbol ]
]

{ #category : 'instance creation' }
Expand Down Expand Up @@ -156,6 +156,13 @@ Symbol class >> possibleSelectorsFor: misspelled [
^ best
]

{ #category : 'symbol table' }
Symbol class >> rawIntern: aStringOrSymbol [

^ (self findInterned: aStringOrSymbol) ifNil: [
NewSymbols add: aStringOrSymbol createSymbol ]
]

{ #category : 'instance creation' }
Symbol class >> readFrom: strm [
"Symbol readFromString: '#abc'"
Expand Down
19 changes: 19 additions & 0 deletions src/Collections-Strings/SymbolTableSemaphore.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"
I am a semaphore to protect the NewSymbols table from concurrent access when new symbols are internalized.
I have a single instance
"
Class {
#name : 'SymbolTableSemaphore',
#superclass : 'Semaphore',
#classVars : [
'SingleInstance'
],
#category : 'Collections-Strings-Base',
#package : 'Collections-Strings',
#tag : 'Base'
}

{ #category : 'instance creation' }
SymbolTableSemaphore class >> singleInstance [
^ SingleInstance ifNil: [ SingleInstance := self forMutualExclusion ]
]

0 comments on commit c0bc5a5

Please sign in to comment.