synchronization

Python shared string memory for multiprocessing

谁都会走 提交于 2019-12-07 07:49:36
问题 I'm trying to use a shared string variable between my Python processes, but it seems that I'm doing something wrong since I'm getting coredumps and invalid memory values. I use multiprocessing.Value to create a ctypes.c_char_p value and use the value attribute to access it. In my understanding of the Python docs the value attribute should be synchronized, as long it is an instance of Value (contrary of an instance of RawValue ). Is that correct so far? I've created a short example to

should I *always* synchronize access to all double field/property/variables that used from more than one thread?

。_饼干妹妹 提交于 2019-12-07 06:18:31
问题 Note I tend to write lock-free code so I try to avoid any types of lock where possible. Instead I just use while(true) loop because I have a lot of CPU power. According to that http://msdn.microsoft.com/en-us/library/aa691278%28VS.71%29.aspx double variable update is not atomic. I'm concerned about two issues: if one thread modify variable of field or property and another thread read it at the same time i want to have either previous or new value, but I don't want to receive something strange

What happens to the lock when thread crashes inside a Synchronized block?

拥有回忆 提交于 2019-12-07 06:13:35
问题 lets say Thread-1 synchronizes on object synchronize(object){ //statement1 //statement2 //statement3 } what happens to the lock on object if Thread-1 crashes on statement2, will JVM release the lock on Thread-1 automatically when this happens ? because otherwise if Thread-2 is wating for the lock on object to be released and Thread-1 crashes, the Thread-2 will wait forever. 回答1: It is defined in the JLS #14.19: synchronized ( Expression ) Block If execution of the Block completes abruptly for

MongoDB synchronize Development and Production databases

浪尽此生 提交于 2019-12-07 05:07:54
问题 We have a dev server which contains a collection of Objects. The actual accumulation of these objects is an ongoing process, which runs a whole process of labelling, verification, etc. on this local dev server. Once these objects are production ready, they are added to the Production DB, which will from that moment, use them in its calculations. I'm looking for a way to simply add the delta (new objects) into the production DB, while retaining all the other collections, and older objects in

Reliable background synchronisation on iOS

谁都会走 提交于 2019-12-07 04:56:00
问题 Preamble I wrote a mobile application which should show upcoming events. The app downloads it's data from server. Data is prepared in batches once every 24 hours and it's ready to be fetched after 4 am. This gives me a perfect opportunity to sync it overnight and to make new data immediately available when the user opens the app. Background fetch This was my first approach for syncing data with the server. It's advertised as very powerful feature, but using it alone (out of the test

Azure inter-role synchronization

末鹿安然 提交于 2019-12-07 04:48:11
问题 I was wondering about the best practices in synchronizing multiple azure instances that run the same role. More precisely, I want to prevent several worker roles to work on the same work-unit. Azure queues do not seem to help on this matter. One option is to use an sql table with locks and stored procedures; but using sql synchronization in Azure seems a bit awkward. Any ideas? Edit, my detailed(but simplified problem) is as follows: There are n targets. A unit of work must be done on each

Thread-safe map with null-key capability

时间秒杀一切 提交于 2019-12-07 04:37:48
问题 I need a multi-threaded Map object to use in my web server's caching, and I need to have null keys. HashMap allows me to have null keys, but ConcurrentHashMap doesn't. I tried to create a synchronized version of HashMap using Collections.synchronizedMap(new HashMap()) but it doesn't accept null keys either. Is there any alternative that I can use, without having to implement some way to wrap the null keys? 回答1: The Map returned by Collections.synchronizedMap supports all of the features of

Block level synchronization

倾然丶 夕夏残阳落幕 提交于 2019-12-07 04:25:06
问题 What is the significance of parameter passed to synchronized? synchronized ( parameter ) { } to achieve block level synchronization. Somewhere i saw code like class test { public static final int lock =1; ... synchronized(lock){ ... } } I don't understand the purpose of this code. Can anyone give me a better example and/or explain it? 回答1: It's the reference to lock on. Basically two threads won't execute blocks of code synchronized using the same reference at the same time. As Cletus says, a

Is this broken double checked locking?

◇◆丶佛笑我妖孽 提交于 2019-12-07 04:15:32
问题 Checkstyle reports this code as "The double-checked locking idiom is broken", but I don't think that my code actually is affected by the problems with double-checked locking. The code is supposed to create a row in a database if a row with that id doesn't exist. It runs in a multi-threaded environment and I want to avoid the primary-key-exists SQL-exceptions. The pseudo-code: private void createRow(int id) { Row row = dao().fetch(id); if (row == null) { synchronized (TestClass.class) { row =

Synchronizing Multiline Textbox Positions in C#

爷,独闯天下 提交于 2019-12-07 03:58:52
问题 I have a C# application wherein there are two multiline textboxes side-by-side, each in one side of a split-container. I would like to synchronize their vertical scroll, so that when the user scrolls up or down one of the textboxes, the other textbox scrolls respectively in the same direction. Is there a way to do this? Thanks. ADDITIONAL INFORMATION - 7/26/10 I found some interesting APIs on the MSDN website: TextBox.GetFirstVisibleLineIndex Method TextBox.GetLastVisibleLineIndex Method