synchronization

Can an Android AsyncTask doInBackground be synchronized to serialize the task execution?

拈花ヽ惹草 提交于 2019-11-26 16:46:14
问题 Is it possible to make AsyncTask.doInBackground synchronized - or achieve the same result in another way? class SynchronizedTask extends AsyncTask { @Override protected synchronized Integer doInBackground(Object... params) { // do something that needs to be completed // before another doInBackground can be called } } In my case, any AsyncTask.execute() can be started before a previous one has completed, but I need to execute the code in doInBackground only after the previous task has finished

Why is double-checked locking broken in Java?

一个人想着一个人 提交于 2019-11-26 16:43:58
问题 This question relates to behaviour of old Java versions and old implementations of the double checked locking algorithm Newer implementations use volatile and rely on slightly changed volatile semantics, so they are not broken. It's stated that fields assignment is always atomic except for fields of long or double. But, when I read an explaination of why double-check locking is broken, it's said that the problem is in assignment operation: // Broken multithreaded version // "Double-Checked

increment a count value outside parallel.foreach scope

梦想与她 提交于 2019-11-26 16:34:39
问题 How can I increment an integer value outside the scope of a parallel.foreach loop? What's is the lightest way to synchronize access to objects outside parallel loops? var count = 0; Parallel.ForEach(collection, item => { action(item); // increment count?? } 回答1: I like to beat dead horses! :) The "lightest" way to increment the count from multiple threads is: Interlocked.Increment(ref count); But as others have pointed out: if you're doing it inside Parallel.ForEach then you're probably doing

How to implement a Lock with a timeout in Python 2.7

半腔热情 提交于 2019-11-26 16:33:20
问题 Is there a way to implement a lock in Python for multithreading purposes whose acquire method can have an arbitrary timeout? The only working solutions I found so far use polling, which I find inelegant and inefficient Doesn't preserve the bounded waiting / progress guarantee of the lock as a solution to the critical section problem Is there a better way to implement this? 回答1: to elaborate on Steven's comment suggestion: import threading import time lock = threading.Lock() cond = threading

high frequency timing .NET

拈花ヽ惹草 提交于 2019-11-26 16:31:50
问题 I'm looking to create a high frequency callback thread. Essentially I need a function to execute at a regular high frequency (up to 100Hz) interval. I realize that windows has a normal thread execution slice is ~15ms. I would like to specify a regular interval that can be faster than 15ms. This is what I'm trying to accomplish. I have an external device that needs to be messaged at a certain interval. The interval is variable depending on the situation. I expect that I would not ever need

Are LinkedBlockingQueue's insert and remove methods thread safe?

走远了吗. 提交于 2019-11-26 16:12:16
问题 I'm using LinkedBlockingQueue between two different threads. One thread adds data via add , while the other thread receives data via take . My question is, do I need to synchronize access to add and take . Is LinkedBlockingQueue 's insert and remove methods thread safe? 回答1: Yes. From the docs: "BlockingQueue implementations are thread-safe. All queuing methods achieve their effects atomically using internal locks or other forms of concurrency control. However, the bulk Collection operations

Shared-memory IPC synchronization (lock-free)

China☆狼群 提交于 2019-11-26 16:11:43
Consider the following scenario: Requirements: Intel x64 Server (multiple CPU-sockets => NUMA) Ubuntu 12, GCC 4.6 Two processes sharing large amounts of data over (named) shared-memory Classical producer-consumer scenario Memory is arranged in a circular buffer (with M elements) Program sequence (pseudo code): Process A (Producer): int bufferPos = 0; while( true ) { if( isBufferEmpty( bufferPos ) ) { writeData( bufferPos ); setBufferFull( bufferPos ); bufferPos = ( bufferPos + 1 ) % M; } } Process B (Consumer): int bufferPos = 0; while( true ) { if( isBufferFull( bufferPos ) ) { readData(

How to sync SQLite database on Android phone with MySQL database on server?

≡放荡痞女 提交于 2019-11-26 16:11:16
I am developing an android application. I want to update the local SQLite database with MySQL database on server. I am not able to figure out that what is the most appropriate and standardized way to do so? Create a webservice (REST is probably best) and serialize your SQLite/MySQL data and PUT/POST/GET it to/from your web service. This will give you a nice layer of abstraction in case you decide to switch from MySQL to something else server side. You may want to take a look at fyrecloud.com/amsler This is source code for a demonstration Android application that implements MySQL replication

Best tool for synchronizing MySQL databases [closed]

守給你的承諾、 提交于 2019-11-26 16:09:39
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I'm on a little quest of merging the structure of two MySql databases. Is there a tool for this with the might of Red-Gate's SQL

Android: How to get a modal dialog or similar modal behavior?

这一生的挚爱 提交于 2019-11-26 15:47:08
问题 These days I'm working on simulating modal dialog in Android. I've googled a lot, there's much discussions but sadly there's not much options to get it modal. Here's some background, Dialogs, Modal Dialogs and Blockin Dialogs / AlertDialogs: How to "block execution" while dialog is up (.NET-style) There's no straight way to get modal behavior, then I came up with 3 possible solutions, 1. Use a dialog-themed activity, like this thread said, but I still can't make main activity truly wait for