concurrency

Problem with thread-safe queue?

泪湿孤枕 提交于 2021-01-27 18:26:20
问题 I'm trying to write a thread-safe queue using pthreads in c++. My program works 93% of the time. The other 7% of the time it other spits out garbage, OR seems to fall asleep. I'm wondering if there is some flaw in my queue where a context-switch would break it? // thread-safe queue // inspired by http://msmvps.com/blogs/vandooren/archive/2007/01/05/creating-a-thread-safe-producer-consumer-queue-in-c-without-using-locks.aspx // only works with one producer and one consumer #include <pthread.h>

Aws Sqs Consumer - Poll only when messages can be processed immediately

假装没事ソ 提交于 2021-01-27 18:19:53
问题 I'm trying to create an AWS SQS windows service consumer that will poll messages in batch of 10. Each messages will be executed in its own task for parallel execution. Message processing includes calling different api's and sending email so it might take some time. My problem is that first, I only want to poll the queue when 10 messages can be processed immediately. This is due to sqs visibility timeout and having the received messages "wait" might go over the visibility timeout and be "back"

java threads don't see shared boolean changes

三世轮回 提交于 2021-01-27 12:08:08
问题 Here the code class Aux implements Runnable { private Boolean isOn = false; private String statusMessage; private final Object lock; public Aux(String message, Object lock) { this.lock = lock; this.statusMessage = message; } @Override public void run() { for (;;) { synchronized (lock) { if (isOn && "left".equals(this.statusMessage)) { isOn = false; System.out.println(statusMessage); } else if (!isOn && "right".equals(this.statusMessage)) { isOn = true; System.out.println(statusMessage); } if

java threads don't see shared boolean changes

拥有回忆 提交于 2021-01-27 12:08:04
问题 Here the code class Aux implements Runnable { private Boolean isOn = false; private String statusMessage; private final Object lock; public Aux(String message, Object lock) { this.lock = lock; this.statusMessage = message; } @Override public void run() { for (;;) { synchronized (lock) { if (isOn && "left".equals(this.statusMessage)) { isOn = false; System.out.println(statusMessage); } else if (!isOn && "right".equals(this.statusMessage)) { isOn = true; System.out.println(statusMessage); } if

ThreadPoolExcutor and invokeAll list order

北城余情 提交于 2021-01-27 11:29:40
问题 I'm working on ThreadPoolExcutor . I would like to know if in invokeAll method, I can be sure that the output ( Future objects) order is going to be the same as the input ( Callable list). List<Future<T>> invokeAll(List<Callable<T>> tasks) 回答1: What is guaranteed is that the list of futures returned has the same order that the list's iterator you're giving. Note that this method only returns when all tasks have been completed. Quoting invokeAll(tasks) Javadoc: Returns: a list of Futures

ThreadPoolExcutor and invokeAll list order

眉间皱痕 提交于 2021-01-27 11:23:31
问题 I'm working on ThreadPoolExcutor . I would like to know if in invokeAll method, I can be sure that the output ( Future objects) order is going to be the same as the input ( Callable list). List<Future<T>> invokeAll(List<Callable<T>> tasks) 回答1: What is guaranteed is that the list of futures returned has the same order that the list's iterator you're giving. Note that this method only returns when all tasks have been completed. Quoting invokeAll(tasks) Javadoc: Returns: a list of Futures

Add delay to parallel API call

↘锁芯ラ 提交于 2021-01-27 07:35:04
问题 I'm using Polly to make parallel API calls. The server however can't process more than 25 calls per second and so I'm wondering if there is a way to add a 1s delay after each batch of 25 calls? var policy = Policy .Handle<HttpRequestException>() .RetryAsync(3); foreach (var mediaItem in uploadedMedia) { var mediaRequest = new HttpRequestMessage { *** } async Task<string> func() { var response = await client.SendAsync(mediaRequest); return await response.Content.ReadAsStringAsync(); } tasks

Add delay to parallel API call

六眼飞鱼酱① 提交于 2021-01-27 07:33:21
问题 I'm using Polly to make parallel API calls. The server however can't process more than 25 calls per second and so I'm wondering if there is a way to add a 1s delay after each batch of 25 calls? var policy = Policy .Handle<HttpRequestException>() .RetryAsync(3); foreach (var mediaItem in uploadedMedia) { var mediaRequest = new HttpRequestMessage { *** } async Task<string> func() { var response = await client.SendAsync(mediaRequest); return await response.Content.ReadAsStringAsync(); } tasks

Is there a way to release the file lock for a xarray.Dataset?

ぃ、小莉子 提交于 2021-01-27 07:29:27
问题 I have a process that grows a NetCDF file fn every 5 minutes using netcdf4.Dataset(fn, mode=a) . I also have a bokeh server visualization of that NetCDF file using a xarray.Dataset (which I want to keep, because it is so convenient). The problem is that the NetCDF-update-process fails when trying to add new data to fn if it is open in my bokeh server process via ds = xarray.open_dataset(fn) If I use the option autoclose ds = xarray.open_dataset(fn, autoclose=True) updating fn with the other

Add delay to parallel API call

烂漫一生 提交于 2021-01-27 07:28:41
问题 I'm using Polly to make parallel API calls. The server however can't process more than 25 calls per second and so I'm wondering if there is a way to add a 1s delay after each batch of 25 calls? var policy = Policy .Handle<HttpRequestException>() .RetryAsync(3); foreach (var mediaItem in uploadedMedia) { var mediaRequest = new HttpRequestMessage { *** } async Task<string> func() { var response = await client.SendAsync(mediaRequest); return await response.Content.ReadAsStringAsync(); } tasks