double-checked-locking Questions
9
Solved
I came across this article discussing why the double-check locking paradigm is broken in Java. Is the paradigm valid for .NET (in particular, C#), if variables are declared volatile?
Spermatophyte asked 27/12, 2008 at 11:5
8
Solved
From Head First design patterns book, the singleton pattern with double checked locking has been implemented as below:
public class Singleton {
private volatile static Singleton instance;
priva...
Diffractometer asked 21/10, 2011 at 21:53
2
Solved
The question is rather easy, in a way. Suppose I have this class:
static class Singleton {
}
And I want to provide a singleton factory for it. I can do the (probably) obvious. I am not going to m...
Kristelkristen asked 6/12, 2020 at 18:57
2
Solved
I saw answers like these, tried to clarify via comments, and was unsatisfied by examples here.
Maybe it's time for this specific question...
Why enum singleton implementation is called lazy?
public...
Faxen asked 24/9, 2020 at 17:53
5
Solved
I read this question about how to do Double-checked locking:
// Double-check idiom for lazy initialization of instance fields
private volatile FieldType field;
FieldType getField() {
FieldType re...
Trinl asked 26/4, 2015 at 20:54
1
Solved
I have implemented what I think is a double check locking in a class to achieve thread safe lazy loading.
Just in case you wondered, this is for a DI library I'm currently working on.
The code ...
Houseleek asked 10/6, 2018 at 0:45
5
Solved
My team is currently debating this issue.
The code in question is something along the lines of
if (!myDictionary.ContainsKey(key))
{
lock (_SyncObject)
{
if (!myDictionary.ContainsKey(key))
{...
Cattier asked 16/5, 2011 at 14:20
2
Solved
I have read many questions considering thread-safe double checked locking (for singletons or lazy init). In some threads, the answer is that the pattern is entirely broken, others suggest a solutio...
Whitish asked 6/9, 2012 at 14:10
1
Solved
I found this article, but it looks wrong because Cell does not guarantee a synchronization between the set() under a lock and the get() over the lock.
Does Atomic_.store(true, Ordering::Release) a...
Severen asked 14/8, 2017 at 19:15
11
I happened upon an article recently discussing the double checked locking pattern in Java and its pitfalls and now I'm wondering if a variant of that pattern that I've been using for years now is s...
Hardman asked 26/10, 2009 at 14:24
5
Solved
private volatile static Singleton uniqueInstance
In a singleton when using double lock method for synchronization why is the single instance declared as volatile ? Can I achieve the same fu...
Excursive asked 24/7, 2012 at 21:40
1
Solved
Regarding a previous question I raised,
public static Singleton getInstanceDC() {
if (_instance == null) { // Single Checked (1)
synchronized (Singleton.class) {
if (_instance == null) { // D...
Keyboard asked 30/10, 2015 at 3:3
1
Back to concurrency. By now it is clear that for the double checked locking to work the variable needs to be declared as volatile. But then what if double checked locking is used as below.
class T...
Legra asked 26/10, 2015 at 16:12
5
Solved
I saw some examples in java where they do synchronization on a block of code to change some variable while that variable was declared volatile originally .. I saw that in an example of singleton cl...
Prosser asked 12/3, 2012 at 10:35
4
Solved
An example in Meyers's book Effective Modern C++, Item 16.
in a class caching an expensive-to-compute int, you might try to use a
pair of std::atomic avriables instead of a mutex:
class Widg...
Anthropophagi asked 5/5, 2015 at 8:49
1
Solved
In this link i found the singleton instantiation as below:
public static Singleton getInstanceDC() {
if (_instance == null) { // Single Checked (1)
synchronized (Singleton.class) {
if (_instanc...
Platinous asked 16/3, 2015 at 16:48
1
Solved
For threadsafe lazy initialization, should one prefer a static variable inside a function, std::call_once, or explicit double checked locking? Are there any meaningful differences?
All three can b...
Gaucho asked 24/9, 2014 at 9:43
1
Solved
I have a multithreaded application and a singleton class:
public final class Singleton {
private static MyClass mc;
public static final Object getInstance() {
if(mc == null) {
mc = new MyCla...
Airport asked 6/11, 2014 at 21:49
2
At the about bottom of http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html, it says:
Double-Checked Locking Immutable Objects
If Helper is an immutable object, such that ...
Saveall asked 28/10, 2014 at 15:15
2
Solved
In C++ and the Perils of Double-Checked Locking, there's persudo code to implement the pattern correctly which is suggested by the authors. See below,
Singleton* Singleton::instance () {
Singleto...
Unitive asked 19/2, 2011 at 12:26
3
Solved
I need to lazily initialize a map and its contents. I have the below code till now:
class SomeClass {
private Map<String, String> someMap = null;
public String getValue(String key) {
if ...
Bootlace asked 22/5, 2014 at 13:1
5
Solved
I came accross this on the Mike Ash "Care and feeding of singletons" and was a little puzzeled by his comment:
This code is kind of slow, though.
Taking a lock is somewhat expensive.
Making it...
Sortition asked 10/3, 2010 at 16:53
2
Solved
According to many, the somewhat common Double-Checked Locking idiom is broken for java unless you're running 1.5 or later and use the volatile keyword.
A broken double-checked lock sample:
// Bro...
Capitalization asked 19/4, 2011 at 13:26
3
Solved
The new machine model of C++11 allows for multi-processor systems to work reliably, wrt. to reorganization of instructions.
As Meyers and Alexandrescu pointed out the "simple" Double-Checked Locki...
Forbes asked 15/5, 2011 at 13:38
1
Solved
In an article on the double-checked locking idiom, I found this quote:
One special case of lazy initialization that does work as expected without synchronization is the static singleton. When th...
Ermeena asked 2/2, 2013 at 0:26
1 Next >
© 2022 - 2024 — McMap. All rights reserved.