synchronization

How to account for clock offsets in a distributed system?

≡放荡痞女 提交于 2019-12-23 18:53:30
问题 Background I have a system consisting of several distributed services, each of which is continuously generating events and reporting these to a central service. I need to present a unified timeline of the events, where the ordering in the timeline corresponds to the moment event occurred. The frequency of event occurrence and the network latency is such that I cannot simply use time of arrival at the central collector to order the events. E.g. in the following scenario: E1 needs to be

OpenCL and GPU global synchronization

自古美人都是妖i 提交于 2019-12-23 17:45:06
问题 Has anyone tried the gpu_sync functions described in the article "Inter-Block GPU Communication via Fast Barrier Synchronization"? All the codes described seems pretty simple and easy to implement but it keeps freezing up my GPU. I'm sure I'm doing something stupid but I can't see what. Can anyone help me? The strategy I'm using is the one described in the section “GPU Lock-Free Synchronization” and here is the OpenCL source code I've implemented: static void globalSync(uint iGoalValue,

What cause java.util.concurrentmodificationexception using Collections.synchronizedList?

China☆狼群 提交于 2019-12-23 17:22:55
问题 I have the following code which gives a java.util.concurrentmodificationexception. I'm not an expert working with threads, but I thought that if I have a synchronized list, it should be thread safe... EDIT: This is the full code of my method. @Override protected List< ExportSchedule > export( List< ExportSchedule > exportSchedules ) { final HandleSystemDoiAdministrator handleSystemDoiAdministrator = HandleSystemDoiAdministratorFactory.getInstance(); final List< ExportSchedule >

Guard simple list in threaded programming?

最后都变了- 提交于 2019-12-23 16:07:22
问题 I'm reading a POSIX threading book for some practice, and I was trying to work out where I'd need mutex guards in a simple singly-linked list as a little practice problem. For example, if I had a list of node structures: template <typename T> struct Node { Node<T>* next; T data; }; Node<T>* head = NULL; //Populate list starting at head... [HEAD] --> [NEXT] --> [NEXT] --> [NEXT] --> [...] --> [NULL] and I had two or more threads. Any thread can insert, delete, or read at any point in the list.

best/simplest way to keep multiple (non-bare) Git repos in sync

岁酱吖の 提交于 2019-12-23 15:24:38
问题 I have several non-bare Git repositories. There is one central Git repository (or at least handled as being the central repo; this might change) but this is also non-bare (because I want to have a checkout on the same machine). My history is mostly linear and I'm the only person who will ever do changes on this repository, so it is unlikely that conflicts will happen. (It is my documents directory.) Pushing directly into another non-bare repository doesn't work if I use the master branch

Using EnterCriticalSection in Thread to update VCL label

本小妞迷上赌 提交于 2019-12-23 15:05:05
问题 I'm new to threads. I'm using a 3rd party library that uses threads which at times call a procedure I've provided. How do I update update a TLabel.Caption from my procedure when its called by the thread? If I've called InitializeCriticalSection elsewhere, is it as simple as EnterCriticalSection(CritSect); GlobalVariable := 'New TLabel.Caption'; LeaveCriticalSection(CritSect); And then in my main thread: EnterCriticalSection(CritSect); Label1.Caption:= GlobalVariable; LeaveCriticalSection

Wait for ANY thread to finish, not ALL

空扰寡人 提交于 2019-12-23 13:06:27
问题 I'm starting multiple threads and would like to know when any of then finishes. I know the following code: foreach (Thread t in threads) t.Join(); But it will only wait for all threads together. That's much too late. I need to know when one thread finishes, even when other threads are still running. I'm looking for something equivalent to WaitAny only for threads. But I can't add code to all threads I'm monitoring, so using signals or other synchronisation objects is not an option. Some

Migrating lock to TPL

别等时光非礼了梦想. 提交于 2019-12-23 12:08:33
问题 In normal C# we write int DoSomething(){/*...*/)}; lock(mutex) { return DoSomething(); } to ensure in all cases the mutex is released. But if the signature of DoSomething changed to Task<int> DoSomeThingAsync(){/*...*/}; Does the following code return Task.Factory.StartNew(() => { Monitor.Enter(mutex); return DoSomethingAsync(); }).Unwrap().ContinueWith(t => { Monitor.Exit(mutex); return t; }).Unwrap(); do similar things? Is it guaranteed to release the mutex whenever it was entered? Are

visibility of side effects when creating and joining threads

旧城冷巷雨未停 提交于 2019-12-23 12:07:34
问题 When are writes that are performed by one thread visible to a different thread when there are no synchronized blocks and no volatile variables? Here is a simplified quicksort example: int middle = partitionForTheFirstTime(array); Thread t = new Thread(new Quicksorter(array, 0, middle - 1)); Thread u = new Thread(new Quicksorter(array, middle + 1, array.size - 1)); t.start() u.start(); t.join(); u.join(); (For the sake of simplicity, assume that the two "worker threads" do not spawn any

Android synchronized onSensorChanged?

对着背影说爱祢 提交于 2019-12-23 10:51:39
问题 This is a followup to my question here: Android thread runnable performance I'm having some difficulty wrapping my head around synchronized methods for my app I'm polling the sensors and storing the sensor values into arrays whenever they change float[] accelerometerMatrix = new float[3]; float[] accelerometerWorldMatrix = new float[3]; float[] gyroscopeMatrix = new float[3]; float[] gravityMatrix = new float[3]; float[] magneticMatrix = new float[3]; float[] rotationMatrix = new float[9];