synchronization

Best Practice for synchronizing common distributed data

二次信任 提交于 2019-12-20 12:01:10
问题 I have a internet application that supports offline mode where users might create data that will be synchronized with the server when the user comes back online. So because of this I'm using UUID's for identity in my database so the disconnected clients can generate new objects without fear of using an ID used by another client, etc. However, while this works great for objects that are owned by this user there are objects that are shared by multiple users. For example, tags used by a user

Are final fields really useful regarding thread-safety?

怎甘沉沦 提交于 2019-12-20 10:26:48
问题 I have been working on a daily basis with the Java Memory Model for some years now. I think I have a good understanding about the concept of data races and the different ways to avoid them (e.g, synchronized blocks, volatile variables, etc). However, there's still something that I don't think I fully understand about the memory model, which is the way that final fields of classes are supposed to be thread safe without any further synchronization. So according to the specification, if an

Are final fields really useful regarding thread-safety?

六眼飞鱼酱① 提交于 2019-12-20 10:26:06
问题 I have been working on a daily basis with the Java Memory Model for some years now. I think I have a good understanding about the concept of data races and the different ways to avoid them (e.g, synchronized blocks, volatile variables, etc). However, there's still something that I don't think I fully understand about the memory model, which is the way that final fields of classes are supposed to be thread safe without any further synchronization. So according to the specification, if an

What is the consensus number for semaphores?

一笑奈何 提交于 2019-12-20 09:57:34
问题 (I think that) the consensus number for a mutex is 2. What is the consensus number for semaphores (like in pthread_sem_*)? What is the consensus number for condition variables (like in pthread_cond_*)? 回答1: The consensus number for a mutex would be 1. It's trivially clear that a mutex will be wait-free for a single thread. From its definition, it's also clear that a mutex is no longer wait-free for two threads. The consensus number therefore is >=1 and <2, so it must be 1. Likewise, other

How do you keep two related, but separate, systems in sync with each other?

那年仲夏 提交于 2019-12-20 09:53:36
问题 My current development project has two aspects to it. First, there is a public website where external users can submit and update information for various purposes. This information is then saved to a local SQL Server at the colo facility. The second aspect is an internal application which employees use to manage those same records (conceptually) and provide status updates, approvals, etc. This application is hosted within the corporate firewall with its own local SQL Server database. The two

What is Test-and-Set used for?

。_饼干妹妹 提交于 2019-12-20 09:53:07
问题 After reading the Test-and-Set Wikipedia entry, I am still left with the question "What would a Test-and-Set be used for?" I realize that you can use it to implement Mutex (as described in wikipedia), but what other uses does it have? 回答1: You use it any time you want to write data to memory after doing some work and make sure another thread hasn't overwritten the destination since you started. A lot of lock/mutex-free algorithms take this form. 回答2: A good example is "increment." Say two

What is Test-and-Set used for?

耗尽温柔 提交于 2019-12-20 09:51:17
问题 After reading the Test-and-Set Wikipedia entry, I am still left with the question "What would a Test-and-Set be used for?" I realize that you can use it to implement Mutex (as described in wikipedia), but what other uses does it have? 回答1: You use it any time you want to write data to memory after doing some work and make sure another thread hasn't overwritten the destination since you started. A lot of lock/mutex-free algorithms take this form. 回答2: A good example is "increment." Say two

On XP, best way to synchronize files and folders [closed]

前提是你 提交于 2019-12-20 09:45:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I'm using SyncToy 1.4 and it would be fine for what I need except that: It can't handle the assigned drive letter changing between systems (e.g. syncing a USB drive), it leaves its own (hidden) files in the folders being synched (is this a limitation of the OS/FS?), it recreates empty folders for ones that have

Waiting on a condition in a reentrant lock

◇◆丶佛笑我妖孽 提交于 2019-12-20 09:29:31
问题 The following code is taken from the JavaDoc of Condition: class BoundedBuffer { final Lock lock = new ReentrantLock(); final Condition notFull = lock.newCondition(); final Condition notEmpty = lock.newCondition(); final Object[] items = new Object[100]; int putptr, takeptr, count; public void put(Object x) throws InterruptedException { lock.lock(); try { while (count == items.length) notFull.await(); items[putptr] = x; if (++putptr == items.length) putptr = 0; ++count; notEmpty.signal(); }

Client-server synchronization over REST

我的梦境 提交于 2019-12-20 09:25:09
问题 This question is about what I think is a very common problem in Android / iOS development but I haven't found any "standard" solution yet. Let's say we have a fairly normal REST API. The server database contains (among others) the tables countries and towns with a 1:N relationship. The client (mobile app) wants to maintain a local snapshot of these two tables. So that when it's offline, it can do queries that would be normally done over REST, e.g.: "get a list of Austrian towns with