Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI do not wish to use the get() function - mainly because it is not generic enough; what happens if I have multiple values (look also at my note)? You are also making two mistakes: your version would deadlock in a self-assignment case and mutex.lock() can throw an exception in your destructor. Finally, I am declaring mutex as mutable, so the const does not create any problems.
      singulars
    2. CO@ipapdop re init: you can still initialize correctly with one acquisition if you create an object to pass as an argument. re deadlocks: it's good to create a second template parameter for the type of lock you'll use, or base classes which are lockable. subclasses with locks are often ideal because you'd rather protect the object's vulnerable state, rather than the members within restricted scopes. attempting to ensure thread safety using a basic mutex for an arbitrary `T` is too often tedious and error prone.
      singulars
    3. CO(cont) a singular interface (as a generic pattern) is very susceptable to deadlocks (some of which will be intensely difficult to reproduce). your example is trivial in comparison to real world usage; a recursive mutex is more practical generalized object lock. it's also best to write/use a few additional objects to convey and enforce your intentions at every stage within the implementation. using `mutable` will only save you from rewriting existing code today. if thread safety and program correctness is your primary concern, i encourage you to omit it.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload