synchronization

Access denied on WaitForSingleObject on an event created from managed code

假如想象 提交于 2021-02-16 19:36:10
问题 How do I create a named event object in C# so that I can wait on it in separate C++ process? My simplified C# code of process A: EventWaitHandle evt = new EventWaitHandle(false, EventResetMode.AutoReset, "eventName"); EventWaitHandle.SignalAndWait(evt , <other event>); And simplified C++ code of process B: HANDLE hEvt = OpenEvent( EVENT_MODIFY_STATE | SYNCHRONIZE, // access FALSE, // do not inherit handle TEXT("eventName") ); if (hEvt == NULL) { printf("CreateEvent failed (%d)\n",

Why memory reordering is not a problem on single core/processor machines?

末鹿安然 提交于 2021-02-16 13:52:07
问题 Consider the following example taken from Wikipedia, slightly adapted, where the steps of the program correspond to individual processor instructions: x = 0; f = 0; Thread #1: while (f == 0); print x; Thread #2: x = 42; f = 1; I'm aware that the print statement might print different values (42 or 0) when the threads are running on two different physical cores/processors due to the out-of-order execution. However I don't understand why this is not a problem on a single core machine, with those

Foreign key reference target does not exist

我们两清 提交于 2021-02-10 16:57:22
问题 I need to synchronize data in two tables from different Firebird databases. Precisely, I need to update records in table Person (1st DB), using records from table Users (2nd DB). Not only "name", "email", "birthday", but ID also (!). The problem is - there are tables, that depend on Person's IDs through FOREIGN KEY Constraint. I'm trying to do this: Drop Foreign Key constraints in dependent tables. Sync two tables (which means renewing/changing IDs in table Person) Change appropriate IDs in

How to synchronise writes from multiple containers to the same volume on a swarm?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-10 15:44:10
问题 Is it safe / possible to use flock in a docker swarm? I'm looking for a safe way for multiple containers to write to the same file (on the same volume). I know that on a single host docker will bind mount. What I'm not certain about is how this works when spinning up containers via docker-compose on a swarm. If I have multiple instances of the same image in a service and these all share a volume then when I start this on a swarm will the containers be started on separate hosts? If so how will

Processing tasks in parallel and sequentially Java

↘锁芯ラ 提交于 2021-02-10 05:35:21
问题 In my program, the user can trigger different tasks via an interface, which take some time to process. Therefore they are executed by threads. So far I have implemented it so that I have an executer with one thread that executes all tasks one after the other. But now I would like to parallelize everything a little bit. i.e. I would like to run tasks in parallel, except if they have the same path, then I want to run them sequentially. For example, I have 10 threads in my pool and when a task

Implement a thread-safe ArrayList in Java by locking

此生再无相见时 提交于 2021-02-09 07:32:19
问题 I want to write a simple thread-safe arraylist which supports: add(), remove(int i), insert(int i), update(int i), and get(int i) One simple implementation is to add lock to the internal data structure(an object array for example), but it is not good enough because only one thread could access the list at a time. Therefore my initial plan is to add lock to each data slot so that different threads could have access to elements in different indexes at the same time. The data structure will look

Implement a thread-safe ArrayList in Java by locking

三世轮回 提交于 2021-02-09 07:31:21
问题 I want to write a simple thread-safe arraylist which supports: add(), remove(int i), insert(int i), update(int i), and get(int i) One simple implementation is to add lock to the internal data structure(an object array for example), but it is not good enough because only one thread could access the list at a time. Therefore my initial plan is to add lock to each data slot so that different threads could have access to elements in different indexes at the same time. The data structure will look

Implement a thread-safe ArrayList in Java by locking

≯℡__Kan透↙ 提交于 2021-02-09 07:27:10
问题 I want to write a simple thread-safe arraylist which supports: add(), remove(int i), insert(int i), update(int i), and get(int i) One simple implementation is to add lock to the internal data structure(an object array for example), but it is not good enough because only one thread could access the list at a time. Therefore my initial plan is to add lock to each data slot so that different threads could have access to elements in different indexes at the same time. The data structure will look

Sync folder of VMWare host and guest

假如想象 提交于 2021-02-08 10:25:03
问题 I am running Win 7 for everyday use, but for development I power up VMWare Workstation 9 with Ubuntu 12.04 LTS installed. What is the easiest way to keep my sourcecode developed in the guest system in sync with the host? (e.g. for the case of guest system failure - I always consider these as disposable.) Approaches I could think of: Some kind of "folder sharing" as known from windows-only networks Using some VM feature to mount a host folder into the guest having an SVN server on the host

Get steady_clock and system_clock at the same time

浪子不回头ぞ 提交于 2021-02-07 18:27:27
问题 My Code looks like: // Next 2 lines should be at the same time auto nowMonotonic = std::chrono::steady_clock::now(); auto nowSystem = std::chrono::system_clock::now(); // Do some calc with nowMonotonic and nowSystem This can happen: auto nowMonotonic = std::chrono::steady_clock::now(); // Some other thread/process interrupts this thread for an // unspecific amount of time... auto nowSystem = std::chrono::system_clock::now(); // Do some calc with nowMonotonic and nowSystem I'm working on a