producer-consumer

Consumer doesn't work in my simple producer/consumer/queue code in Java

时间秒杀一切 提交于 2019-12-08 03:58:05
问题 I am trying to implement a simple producer/consumer system in Java 11. Basically, I take two threads for each, plus a global queue, simply as follows: A global priority queue. The first thread, producer, runs a HTTP server, listens to incoming http messages, and upon receiving a message, pushes it as a job to the queue ( queue.size increments) The second thread, the consumer, continously peeks the queue. If there is a job ( job ! = null ), submits a HTTP request somewhere and upon successful

How to correctly implement triple buffering?

早过忘川 提交于 2019-12-08 02:21:47
问题 I am trying to simulate videocard (producer thread) and a monitor(consumer thread), to figure out what is going on in educational purposes. So here is the technical task description: Producer thread produces frames pixel data at 1000 fps. Consumer thread runs at 60 fps and every frame it must have access to last produced frame for at least 1/60th of second. Each frame is represented by some int* , for simplicity. So my solution is that i have array of 2 pointers: one for producer, one for

Implementing producer consumer in Java

99封情书 提交于 2019-12-07 19:44:34
问题 This is an implementation of producer consumer pattern for a homework. What's wrong with the below implementation. I have googled for various implementations, but I am not able to understand what went wrong in mine. I have a shared queue I synchronize the producer and consumer on the same lock Implementation Shared Queue: class SharedQueue{ public static Queue<Integer> queue = new LinkedList<Integer>(); } Producer Thread : //The producer thread class Producer implements Runnable{ public void

Designing a component both producer and consumer in Kafka

有些话、适合烂在心里 提交于 2019-12-07 18:19:45
问题 I am using Kafka and Zookeeper as the main components of my data pipeline, which is processing thousands of requests each second. I am using Samza as the real time data processing tool for small transformations that I need to make on the data. My problem is that one of my consumers (lets say ConsumerA ) consumes several topics from Kafka and processes them. Basically creating a summary of the topics that are digested. I further want to push this data to Kafka as a separate topic but that

deadlock because of blocking Queue.get() method

前提是你 提交于 2019-12-07 17:03:58
问题 As the title implies I have a deadlock and no idea why. I have multiple producers and only one consumer. The schedule_task method will get called by multiple processes after the thread has called the get method of the queue from logging import getLogger from time import sleep from threading import Event, Thread from multiprocessing import Process from Queue import Queue class TaskExecutor(object): def __init__(self): print("init taskExecutor") self.event = Event() self.taskInfos = Queue()

Producer consumer implementation in a block device driver?

眉间皱痕 提交于 2019-12-07 16:44:53
问题 I'm trying to implement a producer-consumer like situation in my block level driver (on linux kernel version 2.6.39.1). My block driver's make_request_fn receives a stream of struct bio from a userlevel application. On receiving these BIOs, they are queued up. Next, I create a new struct bio which will hold all the information present in the queued BIOs. This new "merged_bio" will be submitted only if there is a struct request slot available in the lower level driver's request_queue . In the

Producer-consumer architecture with Java RealTime

点点圈 提交于 2019-12-07 14:29:55
问题 I am working on designing trade system using Java Realtime ( Sun JRTS 2.2 ) and would like to few questions about best practices, because I am afraid of inventing the wheel and pretty sure that my task was already solved. So I have thread that continuously reading the socket, parsing bytes and extracting messages (binary protocol ). Afterwards, I should send messages to the algorithm, that actually does some calculation and make decision to trade or not. So I think the way I should design

Do I need to use volatile keyword for memory access in critical section?

若如初见. 提交于 2019-12-07 14:21:20
问题 I am writing code for a single processor 32 bit microcontroller using gcc. I need to consume time-stamped objects from a linked list. Another part of the code which could be asynchronous (maybe in an ISR) adds them to the list. The critical section is implemented by turning interrupts off and using the barrier() function. I'm confused where gcc optimization could break my code by cacheing pointers to the list items (next most recent item to remove, list head, or free list). I dont want

Suspend consumer in producer/consumer pattern

允我心安 提交于 2019-12-07 02:39:57
问题 I have producer and consumer connected with BlockingQueue . Consumer wait records from queue and process it: Record r = mQueue.take(); process(r); I need pause this process for a while from other thread. How to implement it? Now I think implement it such, but it's looks like bad solution: private Object mLock = new Object(); private boolean mLocked = false; public void lock() { mLocked = true; } public void unlock() { mLocked = false; mLock.notify(); } public void run() { .... Record r =

Interthread communication

谁都会走 提交于 2019-12-06 16:32:54
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 queue the position data and the main thread would deque the data and act on it. *Note: In Unity I do not