producer-consumer

Multiple Producer Multiple Consumer Multithreading Java

佐手、 提交于 2020-01-01 07:06:47
问题 I'm trying out Multiple Producer - Multiple Consumer use case of Producer-Consumer problem. I'm using BlockingQueue for sharing common queue between multiple producers/consumers. Below is my code. Producer import java.util.concurrent.BlockingQueue; public class Producer implements Runnable { private BlockingQueue inputQueue; private static volatile int i = 0; private volatile boolean isRunning = true; public Producer(BlockingQueue q){ this.inputQueue=q; } public synchronized void run() { /

Go: One producer many consumers

南楼画角 提交于 2019-12-31 12:35:54
问题 So I have seen a lot of ways of implementing one consumer and many producers in Go - the classic fanIn function from the Concurrency in Go talk. What I want is a fanOut function. It takes as a parameter a channel it reads a value from and returns a slice of channels that it writes copies of this value to. Is there a correct/recommended way of implementing this? 回答1: You pretty much described the best way to do it but here is a small sample of code that does it. Go playground: https://play

Observing changes in a BlockingCollection without consuming

只愿长相守 提交于 2019-12-24 14:28:17
问题 A consumer thread and multiple producer threads synchronize their work with a System.Collections.Concurrent.BlockingCollection<T>. The producers call blockingCollection.Add() and the consumer runs foreach (var item in blockingCollection.GetConsumingEnumerable()) {...} Now one producer wants to "flush" the buffer: The producer wants to wait until all current items have been consumed. Other producers may add further items in the meantime, but this producer is only interested in the items that

Producer Consumer using semaphores and mutexes in Python

社会主义新天地 提交于 2019-12-24 03:52:40
问题 I'm trying to understand how to implement a Queue with a bounded buffer size that can be used by multiple producers and consumers using Python Semaphores. Here's my implementation: class Q: def __init__(self, size): self.buff = [None]*size self.end = 0 self.start = 0 self.size = size self.end_lock = Lock() # protect end from race across multiple producers self.start_lock = Lock() # protect start from race across multiple consumers self.open = Semaphore(size) # block till there's space to

OpenMP Producer-Consumer unexpected result

≯℡__Kan透↙ 提交于 2019-12-23 20:12:36
问题 I am working on a simple producer-consumer problem, using OpenMP in C. My program creates 4 threads, two of which are consumers and two producers. Each producer places a character in a buffer, and the consumers just print the character. My aim is to synchronize the producers/consumers so that each producer will produce the next in order character of the alphabet and each consumer will print the next in order character that is placed in the buffer. This is my code: #include <stdio.h> #include

How to detect alarm-based blocking RabbitMQ producer?

僤鯓⒐⒋嵵緔 提交于 2019-12-23 03:52:11
问题 I have a producer sending durable messages to a RabbitMQ exchange. If the RabbitMQ memory or disk exceeds the watermark threshold, RabbitMQ will block my producer. The documentation says that it stops reading from the socket, and also pauses heartbeats. What I would like is a way to know in my producer code that I have been blocked. Currently, even with a heartbeat enabled, everything just pauses forever. I'd like to receive some sort of exception so that I know I've been blocked and I can

Interthread communication

China☆狼群 提交于 2019-12-23 02:59:13
问题 The following question is about the unity game engine, but it could relate to any program trying to send data to a main thread, such as the UI thread. I am processing some data on a separate thread (position data a read asyncrously from a socket). However, I need to act on this data on the main thread (a game object's transform can only be accessed from the main thread). The approach I have in mind is to create a thread-safe queue and follow the producer-consumer pattern. The thread would

Event-based multithread producer-consumer?

浪子不回头ぞ 提交于 2019-12-23 02:51:33
问题 I wish to figure out how to create a multithreaded producer/consumer program where producing is based on an external event. I have built a synchronized queue having 2 thread loops, one to enqueue and one to dequeue and write into a file, with classic pattern: Class SyncQueue { ... producerThread = new Thread(new ThreadStart(StartProducer)); consumerThread = new Thread(new ThreadStart(StartConsumer)); ... public void Start() { producerThread.Start(); consumerThread.Start(); } public void

Kafka consumer not able to consume messages using bootstrap server name

前提是你 提交于 2019-12-23 02:33:28
问题 I am facing an issue while consuming message using the bootstrap-server i.e. Kafka server. Any idea why is it not able to consume messages without zookeeper? Kafka Version: kafka_2.11-1.0.0 Zookeeper Version: kafka_2.11-1.0.0 Zookeeper Host and port: zkp02.mp.com:2181 Kafka Host and port: kfk03.mp.com:9092 Producing some message: [kfk03.mp.com ~]$ /bnsf/kafka/bin/kafka-console-producer.sh --broker-list kfk03.mp.com:9092 --topic test >hi >hi Consumer not able to consume messages if I give –

Non blocking and reoccurring producer/consumer notifier implementation

梦想与她 提交于 2019-12-22 13:06:35
问题 Searched hard for a piece of code which does what i want and i am happy with. Reading this and this helped a lot. I have a scenario where i need a single consumer to be notified by a single producer when new data is available but would also like the consumer to be notified periodically regardless of if new data is available. It is fine if the consumer is notified more than the reoccurring period but it should not be notified less frequent. It is possible that multiple notifications for 'new