concurrency

Parallel Programming With Recursive Functions?

£可爱£侵袭症+ 提交于 2019-12-31 10:57:10
问题 Background of the Problem: I'm trying to write a puzzle solution algorithm that takes advantage of multi-core processors and parallel processing. However, the ideal/easiest solution is a simple recursive function. What's the best way to break down the solution to both take advantage of parallel processing AND the recursive function? The code below is a solution for a simple puzzle solving algorithm (it works correctly). The puzzle in this example is straightforward - there are 14 slots

Spring: Singleton/session scopes and concurrency

为君一笑 提交于 2019-12-31 10:01:55
问题 Does singleton/session scopes of Spring beans require that access to all its fields must be synchronized? Say through "synchronized" keyword or using some classes from package "java.util.concurrent". As example, is this code not thread safe? (copy/pased from here): @Component @SessionScoped public class ShoppingCart { private List<Product> items = new ArrayList<Product>(); public List<Product> getAllItems() { return items; } public void addItem(Product item) { items.add(item); } } 回答1: When

iOS GCD: Difference between any global queue and the one with background priority (DISPATCH_QUEUE_PRIORITY_BACKGROUND)?

筅森魡賤 提交于 2019-12-31 08:55:08
问题 I am reading Concurrency Programming Guide and things confuse me. I see a lot of code invoking the following for any background task: dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); Now what I mean by 'background' is the popular meaning: Something that gets executed anywhere other than the main (UI) thread So following the docs, the above statement returns any non-main-thread queue with differing priorities. My question is - why does then DISPATCH_QUEUE_PRIORITY_BACKGROUND

ExecutorService, standard way to avoid to task queue getting too full

允我心安 提交于 2019-12-31 08:44:19
问题 I am using ExecutorService for ease of concurrent multithreaded program. Take following code: while(xxx) { ExecutorService exService = Executors.newFixedThreadPool(NUMBER_THREADS); ... Future<..> ... = exService.submit(..); ... } In my case the problem is that submit() is not blocking if all NUMBER_THREADS are occupied. The consequence is that the Task queue is getting flooded by many tasks. The consequence of this is, that shutting down the execution service with ExecutorService.shutdown()

Twisted or Celery? Which is right for my application with lots of SOAP calls?

陌路散爱 提交于 2019-12-31 08:44:06
问题 I'm writing a Python application that needs both concurrency and asynchronicity. I've had a few recommendations each for Twisted and Celery, but I'm having trouble determining which is the better choice for this application (I have no experience with either). The application (which is not a web app) primarily centers around making SOAP calls out to various third party APIs. To process a given piece of data, I'll need to call several APIs sequentially. And I'd like to be able to have a pool of

Triggering asynchronous event in gui thread

假装没事ソ 提交于 2019-12-31 07:47:06
问题 TL;DR I'm looking for a way to have one thread raise an event in another EDIT: I say the word "immediate", which is, as some commenters have pointed out, impossible. What I mean is that it should happen reasonably quickly, in the low milli to nanosecond range if the gui thread is idle (which , if I do my job right, it should be). The case example: I have a project which has a Parent class. That Parent class creates a child thread 'Gui', which houses a javafx application and implements

How can I send non-static data to a thread in Rust and is it needed in this example?

回眸只為那壹抹淺笑 提交于 2019-12-31 07:29:50
问题 I am trying to fire up a new thread using some heap data in Rust and I am getting a bunch of errors that stem from the need of the data to have 'static lifetime. I've worked my way backwards up my program but hit a problem. use std::sync::Arc; use std::thread; struct ThreadData { vector_of_strings: Vec<String>, terms: Vec<&'static str>, quotient: usize, } fn perform_search(slice: &[String], terms: &[&str]) { /* ... */ } fn threaded_search(td_arc: &Arc<ThreadData>) { let no_of_lines = td_arc

Do async in a blocking program language way?

帅比萌擦擦* 提交于 2019-12-31 05:39:26
问题 Sync way For example, ruby: con = Mysql.new('localhost') rs1 = con.query('select * from test01') # A rs2 = con.query('select * from test02') # B rs = getResult(rs1, rs2) # C con.close so A will block the execution. B will be executed until A is done. So does C Async way for example, nodejs var mysql = require('mysql'); var connection = mysql.createConnection({host : 'localhost',}); connection.connect(); connection.query('SELECT * from test01', function(err, rows, fields) { console.log(rows);

Issue with single document concurrent read and write operations in mongodb / node.js

为君一笑 提交于 2019-12-31 05:18:23
问题 Edit 6/15 I tried to run the same code adding a delay before calling $doSafePush() again when receiving a ConcurrencyDBError (i.e. doing return when.resolve("wait").delay(35).then(function() {$doSafePush(err.object, "set", value, retries-1);}); instead of return $doSafePush(err.object, "set", value, retries-1); ). It then works just fine as long as I wait for at least 35ms; below that threshold it works sometimes . Feels like magic number but it's working... Still would be interested in

Why is my promise not running synchronously?

巧了我就是萌 提交于 2019-12-31 04:31:07
问题 Have looked around and can't quite find the answer. I am trying to run a promise which executes a fulfil statement once all facebook api pages have been iterated through and saved to an array. I know the function's ugly but I'm having a go to see how far I can get with promises. function pageThroughLikes(facebookPostArray) { var testArray = [] return new Promise(function (fulfill, reject) { facebookPostArray.forEach(function(array) { array.forEach(function(innerObject) { if ('likes' in