synchronization

How and When to Use @async and @sync in Julia

房东的猫 提交于 2019-11-27 19:24:11
I have read the documentation for the @async and @sync macros but still cannot figure out how and when to use them, nor can I find many resources or examples for them elsewhere on the internet. My immediate goal is to find a way to set several workers to do work in parallel and then wait until they have all finished to proceed in my code. This post: Waiting for a task to be completed on remote processor in Julia contains one successful way to accomplish this. I had thought it should be possible using the @async and @sync macros, but my initial failures to accomplish this made me wonder if I am

std::mutex performance compared to win32 CRITICAL_SECTION

若如初见. 提交于 2019-11-27 19:18:44
how does the performance of std::mutex compared to CRITICAL_SECTION ? is it on par? I need lightweight synchronization object (doesn't need to be an interprocess object) is there any STL class that close to CRITICAL_SECTION other than std::mutex ? Please see my updates at the end of the answer, the situation has dramatically changed since Visual Studio 2015. The original answer is below. I made a very simple test and according to my measurements the std::mutex is around 50-70x slower than CRITICAL_SECTION . std::mutex: 18140574us CRITICAL_SECTION: 296874us Edit: After some more tests it turned

fs.writeFile in a promise, asynchronous-synchronous stuff

江枫思渺然 提交于 2019-11-27 19:17:55
I need some help with my code. I'm new at Node.js and have a lot of trouble with it. What I'm trying to do: 1) Fetch a .txt with Amazon products (ASINs) ; 2) Fetch all products using the amazon-product-api package; 3) Save each product in a .json file. My code is not working. I think I messed up with this asynchronous-synchronous stuff - help me! var amazon = require('amazon-product-api'); var fs = require('fs'); var client = amazon.createClient({ awsId: "XXX", awsSecret: "XXX", awsTag: "888" }); var array = fs.readFileSync('./test.txt').toString().split('\n'); for (var i = 1; i < array.length

C++ Thread, shared data

我的未来我决定 提交于 2019-11-27 18:32:32
I have an application where 2 threads are running... Is there any certanty that when I change a global variable from one thread, the other will notice this change? I don't have any syncronization or Mutual exclusion system in place... but should this code work all the time (imagine a global bool named dataUpdated ): Thread 1: while(1) { if (dataUpdated) updateScreen(); doSomethingElse(); } Thread 2: while(1) { if (doSomething()) dataUpdated = TRUE; } Does a compiler like gcc optimize this code in a way that it doesn't check for the global value, only considering it value at compile time

When manipulating different array indices in C/C++ with two threads, is synchronization needed?

浪尽此生 提交于 2019-11-27 18:08:02
问题 Suppose I have an array defined as follows: volatile char v[2]; And I have two threads (denoted by A, B respectively) manipulating array v . If I ensure that A, B use different indices at any time, that is to say, if A is now manipulating v[i] , then B is either doing nothing, or manipulating v[1-i] . I wonder is synchronization needed for this situation? I have referred to this question, however I think it is limited in Java. The reason why I ask this question is that I have been struggling

Is synchronization within an HttpSession feasible?

跟風遠走 提交于 2019-11-27 18:00:37
UPDATE: Solution right after question. Question: Usually, synchronization is serializing parallel requests within a JVM, e.g. private static final Object LOCK = new Object(); public void doSomething() { ... synchronized(LOCK) { ... } ... } When looking at web applications, some synchronization on "JVM global" scope is maybe becoming a performance bottleneck and synchronization only within the scope of the user's HttpSession would make more sense. Is the following code a possibility? I doubt that synchronizing on the session object is a good idea but it would be interesting to hear your

More iCloud Core Data synching woes

允我心安 提交于 2019-11-27 17:56:52
So, it finally happened. The worst case scenario for any independent iPhone developer occurred. Several users are reporting complete data loss after upgrading my app. iCloud Core Data sync is not working. My users are using this app partially to run their businesses. This is a truly catastrophic failure . The only iCloud related thing I changed was to add the key-value store to iCloud. The core data code remained exactly the same, same model version (no migration) etc. In my tests everything worked beautifully! But to my dismay, users reported that their data was not there anymore when they

difference between synchronizing a static method and a non static method

久未见 提交于 2019-11-27 17:44:09
What is the difference between synchronizing a static method and a non static method in java?Can anybody please explain with an example. Also is there any difference in synchronizing a method and synchronizing a block of code? Daniel Lundmark I will try and add an example to make this extra clear. As has been mentioned, synchronized in Java is an implementation of the Monitor concept. When you mark a block of code as synchronized you use an object as a parameter. When an executing thread comes to such a block of code, it has to first wait until there is no other executing thread in a

What does 'result' in ExecutorService.submit(Runnable task, T result) do?

余生长醉 提交于 2019-11-27 17:20:56
问题 Looking at the javadocs it just says <T> Future<T> submit(Runnable task, T result) Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion. Parameters: task - the task to submit result - the result to return but what does it do with result? does it store anything there? does it just use the type of result to specify the type of Future<T> ? 回答1: It doesn't do anything with the result -

TSQL mutual exclusive access in a stored procedure

家住魔仙堡 提交于 2019-11-27 17:00:03
问题 Several web servers access a SQL Server to get a numeric code, when this code doesn't exist, it has to be autogenerated by the SQL Server. I need to ensure that even if two concurrent calls come in and the code doesn't exist, only one code is created and both calls return the same code. So I have to do something like this: begin lock if code exists return code else generate code return code end lock I've been reading a little about isolation levels and table locking, but I have a terrible