"in a thread safe singleton does the return have to be inside the synchronized block" Code Answer
Answers related to “in a thread safe singleton does the return have to be inside the synchronized block”
- What does thread safe mean in a PHP context?
- Is the PHP Intl extension thread safe?
- Does ID have to be unique in the whole page?
- Is there an advantage to use a Synchronized Method instead of a Synchronized Block?
- Does <STYLE> have to be in the <HEAD> of an HTML document?
- Return value for function inside a block
- Is HttpSession thread safe, are set/get Attribute thread safe operations?
- Thread safe multitons in Java
- Java Synchronized Block for .class
- Static versus non-static lock object in synchronized block
- Does a dot have to be escaped in a character class (square brackets) of a regular expression?
- Singleton instance declared as static variable of GetInstance method, is it thread-safe?
- How can I force the Action Bar to be at the bottom in ICS?
- How to implement multithread safe singleton in C++11 without using <mutex>
- Where do I get a thread-safe CollectionView?
- Must Spring MVC Classes be Thread-Safe
- Why does changing the returned variable in a finally block not change the return value?
- Is the C# static constructor thread safe?
- What's the best way of implementing a thread-safe Dictionary?
- Does const mean thread-safe in C++11?
- If you overwrite a field in a subclass of a class, the subclass has two fields with the same name(and different type)?
- Is a HashMap thread-safe for different keys?
- Thread Safe singleton class
- Thread Safe C# Singleton Pattern
- Is a volatile int in Java thread-safe?
- Is the += operator thread-safe in Python?
- What is the difference between a synchronized method and synchronized block in Java?
- Does a name attribute have to be unique in a HTML document?
- What does the return keyword do in a void method in Java?
- AsyncTask: where does the return value of doInBackground() go?
- Is it safe to use a boolean flag to stop a thread from running in C#
- What Makes a Method Thread-safe? What are the rules?
- Thread safe lazy construction of a singleton in C++
- Which files in a Visual C# Studio project don't need to be versioned?
- How to implement a unmanaged thread-safe collection when I get this error: <mutex> is not supported when compiling...
- Difference between Synchronized block with wait/notify and without them?
- Why does an NSInteger variable have to be cast to long when used as a format argument?
- Does JSON-LD have to be embedded?
- Pattern for lazy thread-safe singleton instantiation in java
- How to access c# WPF control in thread safe way?
- Delphi: Why VCL is not thread-safe? How can be?
- Is it thread safe to set Active Resource HTTP authentication on a per-user basis?
- Is using a singleton for the connection a good idea in ASP.NET website
- Synchronized block not working
- Thread safe instantiation of a singleton
- How to make a class Thread Safe [closed]
- Writing to file in a thread safe manner
- Thread-safe iteration over a collection
- how in BOOST send a signal in a thread and have the corresponding slot executed in another thread?
- Why does variables in lambdas have to be final or effectively final?
- Is returning local static object thread safe for pre-c++11 compilers
- how to know what is NOT thread-safe in ruby?
- Is there any way to return HTML in a PHP function? (without building the return value as a string)
- Thread Safe Singletons in Java
- Why does the instance need to be recreated when restarting a thread?
- Is this use of a static queue thread-safe?
- When updating an Android app does the APK need to be named the same as the original?
- What is the difference between a synchronized function and synchronized block?
- Which features make a class to be thread-safe?
- Why does Rust not have a return value in the main function, and how to return a value anyway?
- Thread safe singleton in swift
- What is the scope of variables declared inside a static block in java?
- Designing a thread-safe copyable class
- In what situations could an empty synchronized block achieve correct threading semantics?
- Is this Singleton implementation correct and thread-safe?
- how to make a thread-safe global counter in python
- Lazily initialize a Java map in a thread safe manner
- How to make a static Calendar thread safe
- Does Interlocked guarantee visibility to other threads in C# or do I still have to use volatile?
- Is a readonly field in C# thread safe?
- Is ||= in Ruby thread safe?
- Does the pointer passed to free() have to point to beginning of the memory block, or can it point to the interior?
- Would looping Thread.Sleep() be bad for performance when used to pause a thread?
- Clarification on the meaning of the parameter block synchronization
- Does my HTML5 doctype have to be on the VERY first line?
- Does the DOCTYPE declaration have to be the first tag in an HTML document?
- Is the scanner in java not thread safe?
- What is a thread-safe way to read/write a C# property in a class?
- How does the function that is called inside the class declaration?
- Does an HTML5 canvas always have to be a rectangle?
- progressbar in a thread does not update its UI until the work was done in the main thread
- Why can't a 'continue' statement be inside a 'finally' block?
- You have to be inside an angular-cli project in order to use the build command after reinstall of angular-cli
- Does a mercurial subrepository have to be a subdirectory of the main repository?
- How to properly implement ARC compatible and `alloc init` safe Singleton class?
- Kotlin thread safe native lazy singleton with parameter
- How to iterate over a container in a thread-safe way?
- Creating a thread-safe temporary file name
- Are channel/stubs in gRPC thread-safe
- Are functions in the C standard library thread safe?
- In java, return value within synchronized block seems like bad style. Does it really matter?
- Is using `std::get<I>` on a `std::tuple` guaranteed to be thread-safe for different values of `I`?
- Is Initialization On Demand Holder idiom thread safe without a final modifier
- Does a pointer returned by std::string.c_str() or std::string.data() have to be freed?
- Is yield return in C# thread-safe?
- Why does a perfect forwarding function have to be templated?
- Should URLForUbiquityContainerIdentifier: be called in a thread outside the main thread?
- Execution of new thread inside a synchronized block
- How to use an AppDomain to limit a static class' scope for thread-safe use?
- GCC's TSAN reports a data race with a thread safe static local
- Final variable and synchronized block in java
- Using “notify()” & “wait()” instead of “suspend()” and “resume()” to control a thread
- Are Kotlin's singletons thread safe?
- in a for-loop, what does the (int i : tall) do, where tall is an array of int
- How to make a variable thread-safe
- Realm thread safe object with singleton
- Do we need to synchronize writes if we are synchronizing reads?
- synchronized block on grails works on windows but no in linux
- Why does the error “expected to be a reference, value given” appear?
- Why does the suggested Swift singleton implementation use a struct?
- In C# regular expression why does the initial match show up in the groups?
- Setting Time.zone during a request: Thread Safe?
- Is the Microsoft Enterprise Library 5.0 Logging Application Block thread safe?
- Does an OpenID realm have to be the base URL of the web site?
- Why can't Thread.interrupt() interrupt a thread trying to acquire lock
- “the type does not fulfill the required lifetime” when using a method in a thread
- Concurrency in Java using synchronized blocks not giving expected results
- Thread-safe singleton in C++11
- Why do pseudoclasses on the host element have to be inside of the host function?
- VirtualPath in AspNetCompiler MSBuild Task - does it have to be equal to the final deployed Virtual Path?
- Is it thread-safe to read an instance variable while calling a setter from another thread?
- Why cant a thread that is not the UI thread access the view?
- what does the function returns with in C program , in case if there is no return statement in the code
- What is the definition of a thread safe function according to the C++11 (Language/Library) Standard?
- Automatic notify()/notifyAll() on leaving a synchronized block [closed]
- Can a thread call wait() on two locks at once in Java (6)
- What is the Best Practice for thread-safe access to controls
- How does the safe bool idiom bool_type (and the safe bool idiom) work?
- In a business network, how does each peer “get a copy of the ledger”?
- Is the != check thread safe?
- Why does a SOAP message have to be sent over HTTP?
- How to write a thread-safe and efficient, lock-free memory allocator in C?
- Is this design of Spring singleton beans thread safe?
- Is extending a Python list (e.g. l += ) guaranteed to be thread-safe?
- Magical Record - fetch in main thread block ui, in background return nil
- Does every method in main class have to be static?
- With guaranteed copy elision, why does the class need to be fully defined?
- Is working with the Session thread-safe?
- Is the “switch” statement evaluation thread-safe?
- Designing a Thread Safe Class
- How to correctly make a thread safe Singleton Factory in Java?
- why using volatile with synchronized block?
- Is the List<T>.AddRange() thread safe?
- Is CreateDirectory() in C# thread-safe?
- Possible to safely increment BigInteger in a thread safe way, perhaps with AtomicReference, w/o locking?
- Keras “pickle_safe”: What does it mean to be “pickle safe”, or alternatively, “non picklable” in Python?
- Is this stored procedure thread-safe? (or whatever the equiv is on SQL Server)
- You have to be inside an angular-cli project in order to use the serve command
- Does my Return Type Need to be Defined?
- Thread safe singleton implementation in C++
- What are the Dangers of using a Singleton in a multithreaded application
- Does die have to be used if opening a file fails?
- Are Java arrays in a static method thread safe?
- Is the C# '??' operator thread safe?
- pthread_mutex_t VS @synchronized block?
- Functional way to implement a thread safe shared counter
- How to write LINQ query with column name as parameter still in a type safe way
- Is this a valid, lazy, thread-safe Singleton implementation for C#?
- how does the volatile count++ operation be made thread safe
- is this GCD implemented getter setter thread safe and work better than @synchronized? objc
- does the timer thread wait till all the steps in the callback function are done or does the callback function get...
- What does the C++ compiler do to ensure that different but adjacent memory locations are safe to be used on...
- Is Lazy<T> a good solution for a thread safe lazy loaded singleton?
- Does mutation of an non-thread-safe collection in a constructor need to be synchronized?
- Why is the standard C# event invocation pattern thread-safe without a memory barrier or cache invalidation? What...
- Singleton pattern - Does early binding (with static variables involved) diminish the need of mutex locks?
- What's the most CPU-efficient way to “waste time” in a thread?
- AtomicBoolean vs synchronized block
- Is this use of the generic List thread safe
- Why should we make a SessionScoped ManagedBean thread safe in JSF?
- Is returning a slice of a local array in a Go function safe?
- Is entering synchronized block atomic?
- What is the best way to implement a singleton pattern class in Actionscript 3?
- Is it thread safe to call async_send and async_receive at the same time?
- What do the terms synchronized and thread-safe mean? [closed]
- Does every Python function have to return at the end?
- Singleton in Objective-C, compatible with ARC and thread safe
- How does the return statement work in C?
- Synchronized block in the main method
- Does fieldset have to be in a form?
- Is the null coalescing operator (??) in C# thread-safe?
- Are Asynchronous writes to a socket thread safe?
- Does the h1 need to be the first semantic element in a header tag?
- Is this use of PreparedStatements in a Thread in Java correct?
- In Python 3.6, why does a negative number to the power of a fraction return nan when in a numpy array?
- How to know if a Java SE class or method is thread safe?
- Do operations on ThreadLocal have to be synchronized?
- Getting random numbers in a thread-safe way
- Is the ternary operator (?:) thread safe in C#?
- Does a project have to be created as a sprite kit or can the framework simply be added?
- How to use default value in the builder pattern if that value is not passed and also make thread safe?
- I'm trying to get a UILabel to scroll inside of a UIScrollView but it doesnt scroll
- How to return references to object created inside a method
- interrupting a thread after fixed time, does it have to throw InterruptedException?
- How to correctly use VAVR collections to be thread safe?
- How to get return value from a function called which executes in another thread in TBB?
- How to create a thread local variable inside of a Rust struct?
- Is the following utility class thread-safe?
- Is it safe to store an ObjectContext in a thread static variable in ASP.NET?
- When does XPath property have to be set to XML DOM object?
- How can one implement a thread-safe wrapper to maps in Go by locking?
- In a graphics context, what does the term "rubberbanding" mean?
- Does A Web Service Have To Be Registered?
- Does ASP.NET multithreading impact Structuremap singleton class?
- Why can't I directly access (and lock) the implicit lock that Objects use for synchronized block
- In Java, does read only access to Strings need to be synchronized?
- In what cases, a singleton design pattern may generate multiple instances of the same singleton class?
- Where should my Try Catch block be when running a thread?
- When creating thread safe reads in Swift, why is a variable create outside the concurrent queue?
- can some one confirm if this is a thread safe implementation of singleton
- Sign in with apple "invalid_client" on the first redirect to apple of the Oauth2 code grant flow using service...
- Thread safe singleton in C++
- Returning from a DbSet 3 tables without the error "cannot be inferred from the query"
- Does using only immutable data types make a Java program thread safe?
- Simplification of synchronized block in Java
- Method called on thread using Synchronize does not return without moving the mouse
- Thread-safe way to increment and return an integer in Delphi
- Does '#'-character have to be at the start of a line in the C preprocessor?
- Does T have to be a complete type to be used in `std::declval<T>`?
- Proving the following code not thread safe
- How to increment (add value to) decimal in a thread-safe way?
- Is python's "in" language construct thread-safe for lists?
- Is this a thread safe way to initialize a [ThreadStatic]?
- Does the phone need to be connected to the internet so that the network provider can determine a location?
- Eigen library: return a matrix block in a function as lvalue
- Set the transparency of bars in a bar plot and set the y-axis to a log scale - but both don't seem to work in MATLAB
- Does Django OneToOneField needs to be unique?
- Which STL container has a thread-safe insertion process?
- Will a IDisposable be disposed if the using block returns?
- Why does a LESS file have to be set as Build Action "Content" to deploy to Azure?
- DatabaseWrapper objects created in a thread can only be used in that same thread." when trying to insert into...
- Does the waiting thread revisit the code inside synchronized method
- In a js class what is the better way to call super passing all the arguments up to the parent class?
- Does the return process cast/convert the type required to a result according to the C standard, or is that only...
- Microsoft Enterprise Library Caching Application Block not thread safe?
- Do PRNG need to be thread safe?
- T-SQL date range in a table split and add the individual date to the table
- Is implementation of double checked singleton thread-safe?
- How to make a shared resource thread-safe when using dependency injection?
- When I use Binding.scala, I got the error `each instructions must be inside a SDE block`, how can I fix this?
- Delphi 2006 - What's the best way to gracefully kill a thread and still have the OnTerminate handler fire?
- Why I don't need call CoInitialize in a thread created inside a COM Thread?
- Does the device need to be rooted to read '/proc/cpuinfo' on an Android device?
- In a column of numbers, find the closest value to some target value
Only authorized users can answer the Search term. Please sign in first, or register a free account.
returndoes not need to be in the
synchronizedblock unless the
singletonfield can be assigned elsewhere. however, there is no good reason why the
returnshouldn't be inside of the synchronized block. if the entire method is wrapped in a synchronized then you can just mark the method as synchronized if we are in the
singletonclass here. this would be cleaner and better in case singleton gets modified elsewhere.
in terms of why it doesn't need to be inside, since you are using a
synchronizedblock, there is a read-barrier crossed at the start of the block and a write-barrier at the end, meaning that the threads will get the most up-to-date value of
singletonand it will only be assigned once.
the read memory barrier ensures that the threads will see an updated singleton which will either be
nullor a fully published object. the write memory barrier ensures that any updates to
singletonwill be written to main memory which includes the full construction of
singletonand the publishing of it to the
singletonfield. program order guarantees that the
singletonassigned within the
synchronizedblock will be returned as the same value unless there is another assignment in another thread to
singletonthen it will be undefined.
program order would be more in force if you did something like the following. i tend to do this when
volatile(with appropriate double-check locking code).
since you are using a
synchronizedblock, this isn't an issue. the double check locking is all about trying to avoid the
synchronizedblock being hit on every operation as you point out.
that's correct. you aren't wrong.
no reason not to although i would argue that the "safe side" is more about causing consternation when others review this code and are worrying about it in the future, as opposed to being "safer" from the standpoint of the language definition. again, if there are other places where
singletonis assigned then the
returnshould be inside of the