thread-safety

Thread safe lazy initialization on iOS

我与影子孤独终老i 提交于 2019-12-18 12:06:14
问题 I have a view controller that I want to lazily initialize, and once initialized, use the same copy when possible (I don't use a singleton since I do want to remove it from memory eventually), I use the getter to do so, my code look like this: @property (retain) UIViewController *myController ... @synthesize myController = _myController; ... - (UIViewController *)myController { if (!_myController) { // Evaluation _myController = [[MyViewController alloc] init]; // Object Creation } return

How to iterate over a container in a thread-safe way?

痴心易碎 提交于 2019-12-18 11:56:11
问题 I have a container (C++) on which I need to operate in two ways, from different threads: 1) Add and remove elements, and 2) iterate through its members. Clearly, remove element while iteration is happening = disaster. The code looks something like this: class A { public: ... void AddItem(const T& item, int index) { /*Put item into my_stuff at index*/ } void RemoveItem(const T& item) { /*Take item out of m_stuff*/ } const list<T>& MyStuff() { return my_stuff; } //*Hate* this, but see class C

thread safe, stateless design using Spring

对着背影说爱祢 提交于 2019-12-18 11:43:19
问题 I have assumed that if instance variables are managed by spring IOC, and are singletons that the desgin can be called stateless and threadsafe.This type of desgin could consequently be scaled to clustered servers. Am I correct in my assumptions,outlined below ? @Repository("myDao") public class MyDao implements Dao { @Autowired private JdbcTemplate jdbcTemplate; @Value("${sqlFoo}") private String foo; @Override public Integer getMyInt(String str) { return jdbcTemplate.queryForInt(foo, str); }

Is it okay to pass injected EntityManagers to EJB bean's helper classes and use it?

不想你离开。 提交于 2019-12-18 11:35:39
问题 We have some JavaEE5 stateless EJB bean that passes the injected EntityManager to its helpers. Is this safe? It has worked well until now, but I found out some Oracle document that states its implementation of EntityManager is thread-safe. Now I wonder whether the reason we did not have issues until now, was only because the implementation we were using happened to be thread-safe (we use Oracle). @Stateless class SomeBean { @PersistenceContext private EntityManager em; private SomeHelper

Are Delphi simple types thread safe?

ε祈祈猫儿з 提交于 2019-12-18 11:17:18
问题 I declared two global variables: var gIsRunning: Boolean = False; gLogCounter: Integer = 0; These variables are written only in the main thread, and read in other threads. In this case, are these variables thread safe? 回答1: You are probably saying about atomic variables. Integer and Boolean variables are atomic. Booleans (bytes) are always atomic, integers (32-bits) are atomic because the compiler properly aligns them. Atomicity means that any read or write operation is executed as a whole.

non-blocking thread-safe queue in C++?

依然范特西╮ 提交于 2019-12-18 11:10:55
问题 Is there a thread-safe, non-blocking queue class in the C++? Probably a basic question but I haven't been doing C++ for a long time... EDIT: removed STL requirement. 回答1: Assuming your CPU has a double-pointer-wide compare-and-swap (compxchg8b on 486 or higher, compxchg16b on most amd64 machines [not present on some early models by Intel])... There is an algorithm here. Update: It's not hard to translate this to C++ if you aren't afraid of doing a bit of work. :P This algorithm assumes a

difference between standard's atomic bool and atomic flag

守給你的承諾、 提交于 2019-12-18 10:59:21
问题 I wasn't aware of the std::atomic variables but was aware about the std::mutex (weird right!) provided by the standard; however one thing caught my eye: there are two seemingly-same (to me) atomic types provided by the standard, listed below: std::atomic<bool> std::atomic_flag The std::atomic_flag contains the following explanation: std::atomic_flag is an atomic boolean type. Unlike all specializations of std::atomic , it is guaranteed to be lock-free. Unlike std::atomic<bool> , std::atomic

How does Spring bean Handle concurrency

霸气de小男生 提交于 2019-12-18 10:43:06
问题 My web application uses Spring IOC. So all my spring beans will be singletons by default. In case if two requests try to access two different methods of a single class (for example MySpringBean is a class which has two methods searchRecord and insertRecord ) at the same time, both the methods will access the same spring bean concurrently. How does the same spring bean be available to both the clients at the same time or is it going to be concurrency problem when both the requests will try to

How does Spring bean Handle concurrency

﹥>﹥吖頭↗ 提交于 2019-12-18 10:42:25
问题 My web application uses Spring IOC. So all my spring beans will be singletons by default. In case if two requests try to access two different methods of a single class (for example MySpringBean is a class which has two methods searchRecord and insertRecord ) at the same time, both the methods will access the same spring bean concurrently. How does the same spring bean be available to both the clients at the same time or is it going to be concurrency problem when both the requests will try to

Java synchronized method

本秂侑毒 提交于 2019-12-18 10:35:26
问题 Consider this code: public synchronized void onSignalsTimeout(List<SignalSpec> specs) { if (specs != null && specs.size() > 0) { for (SignalSpec spec : specs) { ParsedCANSignal timeoutedSignal = new ParsedCANSignal(); SignalsProvider.getInstance().setSignal(spec.name, spec.parent.parent.channel, timeoutedSignal); } } } I've got simple question: When Thread 1 calls onSignalsTimeout method, can Thread 2 access objects that are accessed in that method? Can't find anywhere if 'synchronized' locks