All Questions
Tagged with lazy-initialization multithreading
23 questions
1
vote
2
answers
193
views
Racy Single-Check Idiom with Intermediate Result
The racy single-check idiom is a technique for lazy initialization without synchronization or volatile. It can be used when initialization is allowed to be performed concurrently by multiple threads, ...
2
votes
0
answers
265
views
How to use Lazy<T>(Func<T> valueFactory) in a way that if init fails It should not use cached exception and should not run multiple threads for init? [duplicate]
How to use Lazy(Func<T> valueFactory) of C# in such a way that, if initialization fails, it should not use cached Exception and at the same time it should not run multiple threads for ...
1
vote
1
answer
371
views
Update method on ConcurrentDictionary implemented with Lazy<T> does not work
As described in this blog article, I used the Lazy<T> class to make my ConcurrentDictionary thread-safe. I created a new class called LazyConcurrentDictionary<TKey, TValue> which stores a ...
3
votes
1
answer
3k
views
Asp.Net Core async lazy initialization per request
For many endpoints in our multi-tenant Asp.Net Core 2.2 web app, we need to get some tenant information from our database on a per-request basis (using an asynchronous database call), then reuse that ...
2
votes
1
answer
1k
views
Share static lazy-initialized object containing `Rc` refs among multiple threads with `thread_local!` and `OnceCell`
I have split my tests into several, similar sections. Within each section, results are compared against a static test string, written in a dedicated tested language (here called dum) and parsed with ...
0
votes
1
answer
73
views
java multithreaded lazily initialized singleton which approach?
Are both the below approaches for lazy-initializing thread-safe singleton in java correct? Is there any performance difference? If not then why do we use the Holder pattern(Singleton2) instead of ...
3
votes
2
answers
1k
views
Get-or-create pattern in Java 7?
I am trying to write a generic functionality that does thread-safe optional lazy initialization on demand. I cannot use the standard pattern, as the value is not final and could have been set via a ...
1
vote
1
answer
1k
views
Does C# lock object require lazy initialization
I may be missing some blindingly obvious documentation somewhere, but is static readonly member variable guaranteed to be initialized properly for use as a lock object?
In short, I have a library ...
3
votes
2
answers
570
views
std::call_once lazy initialization issue on QNX
My code is periodically crashing on QNX. It crashes with error
error reading variable: Cannot access memory at address 0x85dd6ac)
while trying to access std::map member variable of 0x85dd6ac object, ...
3
votes
1
answer
3k
views
Singleton with or without holder = lazy vs eager initialisation?
Is this correct:
Using a singleton with a holder gives lazy initialisation because the class SingletonHolder is only initialised when Singleton.getInstance() is run. This relies on SingletonHolder ...
2
votes
1
answer
354
views
Why don't we require a lazy-init getter to be synchronized (the holder idiom)?
I'm reading J. Bloch's effective Java and now I'm at the section about lazy-initialization. Consider the following class:
public class LazyInit{
public static getObject(){ //Not synchronized
...
0
votes
1
answer
1k
views
C# using Lazy Initialization and lock together
I want some of my objects lazy initialized like:
private static Lazy<MappingEngine> engine = new Lazy<MappingEngine>(() =>
{
return new MappingEngine();
})
And I don't want ...
1
vote
2
answers
1k
views
Implementing a parametrized thread-safe lazy-init cache using ConcurrentHashMap (without volatile keyword)
The single-check idiom can be used to implement a thread safe-lazy init with (compared to the double-check) the possible drawback of wasting some computation time by multiple concurrent inits. It is
...
0
votes
2
answers
130
views
assign value to attribute in other thread
I want to assign value to att = 5 in thread t. In the main thread, I want to check if att has been assigned to 5 yet
When I run the void check(), the output is always 3. Why is this?
class Program
...
28
votes
5
answers
5k
views
Lock-free and wait-free thread-safe lazy initialization
To perform lock-free and wait-free lazy initialization I do the following:
private AtomicReference<Foo> instance = new AtomicReference<>(null);
public Foo getInstance() {
Foo foo = ...