Re: aa.keys, synchronized and shared

2022-11-14 Thread torhu via Digitalmars-d-learn
On Monday, 14 November 2022 at 07:57:16 UTC, Kagamin wrote: This works for me: ``` shared SyncAA!(string,string) saa; void f() { saa=new shared SyncAA!(string,string)("1","2"); saa.keys(); saa["12"]="34"; saa.remove("12"); } ``` The strange error message I got

Re: aa.keys, synchronized and shared

2022-11-14 Thread Kagamin via Digitalmars-d-learn
This works for me: ``` synchronized final class SyncAA(K, V) { this(K key, V val) { sharedTable[key]=val; } V opIndex(K key) { return sharedTable[key]; } V opIndexAssign(V value, K key) { return sharedTable[key]=value; } const(K[]) keys() const { return

Re: aa.keys, synchronized and shared

2022-11-11 Thread torhu via Digitalmars-d-learn
On Friday, 11 November 2022 at 14:19:31 UTC, Kagamin wrote: Try this: ``` private: V[K] sharedTable; ref inout(V[K]) unsharedTable() inout { return *cast(inout(V[K])*) } ``` Thanks, that worked! Feels like programming in C, though. If I could

Re: aa.keys, synchronized and shared

2022-11-11 Thread Kagamin via Digitalmars-d-learn
With allocation: ``` synchronized final class SyncAA(K, V) { V opIndex(K key) { return sharedTable[key]; } V opIndexAssign(V value, K key) { return sharedTable[key]=value; } const(K[]) keys() const { return unsharedTable.keys; } void remove(K key) {

Re: aa.keys, synchronized and shared

2022-11-11 Thread Kagamin via Digitalmars-d-learn
Try this: ``` synchronized final class SyncAA(K, V) { V opIndex(K key) { return sharedTable[key]; } V opIndexAssign(V value, K key) { return sharedTable[key]=value; } const(K[]) keys() const { return unsharedTable.keys; } void remove(K key) { sharedTable.remove(key); }

Re: aa.keys, synchronized and shared

2022-11-10 Thread cc via Digitalmars-d-learn
On Friday, 11 November 2022 at 01:09:54 UTC, torhu wrote: On Thursday, 10 November 2022 at 21:55:26 UTC, torhu wrote: I'm trying to make a more thread-safe wrapper for AA's: ``` synchronized final class SyncAA(K, V) /// I chose to fix this by just using `synchronized (this)` inside each

Re: aa.keys, synchronized and shared

2022-11-10 Thread torhu via Digitalmars-d-learn
On Thursday, 10 November 2022 at 21:55:26 UTC, torhu wrote: I'm trying to make a more thread-safe wrapper for AA's: ``` synchronized final class SyncAA(K, V) /// I chose to fix this by just using `synchronized (this)` inside each method instead, for now. Still interested in cleaner