producer-consumer

does Monitor.Wait Needs synchronization?

断了今生、忘了曾经 提交于 2019-12-17 20:45:39
问题 I have developed a generic producer-consumer queue which pulses by Monitor in the following way: the enqueue : public void EnqueueTask(T task) { _workerQueue.Enqueue(task); Monitor.Pulse(_locker); } the dequeue: private T Dequeue() { T dequeueItem; if (_workerQueue.Count > 0) { _workerQueue.TryDequeue(out dequeueItem); if(dequeueItem!=null) return dequeueItem; } while (_workerQueue.Count == 0) { Monitor.Wait(_locker); } _workerQueue.TryDequeue(out dequeueItem); return dequeueItem; } the wait

Multiple producers, single consumer

杀马特。学长 韩版系。学妹 提交于 2019-12-17 11:52:08
问题 I have to develop a multithreaded application, where there will be multiple threads, each thread generates custom event log which need to be saved in queue (not Microsoft MSMQ). There will be another thread which reads log data from queue and manipulates it, with certain information to save log information into a file. Basically here we are implementing Multiple-producer, Single-consumer paradigm. Can anybody provide suggestions on how to implement this in C++ or C#. Thanks, 回答1: This kind of

C# producer/consumer

末鹿安然 提交于 2019-12-17 00:48:04
问题 i've recently come across a producer/consumer pattern c# implementation. it's very simple and (for me at least) very elegant. it seems to have been devised around 2006, so i was wondering if this implementation is - safe - still applicable Code is below (original code was referenced at http://bytes.com/topic/net/answers/575276-producer-consumer#post2251375) using System; using System.Collections; using System.Threading; public class Test { static ProducerConsumer queue; static void Main() {

C# producer/consumer

我们两清 提交于 2019-12-17 00:47:07
问题 i've recently come across a producer/consumer pattern c# implementation. it's very simple and (for me at least) very elegant. it seems to have been devised around 2006, so i was wondering if this implementation is - safe - still applicable Code is below (original code was referenced at http://bytes.com/topic/net/answers/575276-producer-consumer#post2251375) using System; using System.Collections; using System.Threading; public class Test { static ProducerConsumer queue; static void Main() {

How to end Singleton-object queue if I use Spring AOP cross-cutting concerns + log4net for logging

让人想犯罪 __ 提交于 2019-12-13 16:55:30
问题 I have an application, that use Spring.AOP library to apply proxy-object to log what methods of program do (I use xml-configuration). Before I used log4net to log messages with Spring.AOP(simplified class): public class CommandLoggingAdvice : IMethodInterceptor { // here I get an instance of log4net private ILog _Logger = null; protected ILog Logger { _Logger = LogManager.GetLogger("Logger1"); } public object Invoke(IMethodInvocation invocation) { Logger1.Info("Now we enter to method"); //

Java: High-performance message-passing (single-producer/single-consumer)

删除回忆录丶 提交于 2019-12-13 11:49:37
问题 I initially asked this question here, but I've realized that my question is not about a while-true loop. What I want to know is, what's the proper way to do high-performance asynchronous message-passing in Java? What I'm trying to do... I have ~10,000 consumers, each consuming messages from their private queues. I have one thread that's producing messages one by one and putting them in the correct consumer's queue. Each consumer loops indefinitely, checking for a message to appear in its

How to implement one producer , multiple consumers and multiple Objects in Java?

别来无恙 提交于 2019-12-13 06:32:23
问题 I have a question about Producer/consumer Design pattern , in fact my situation is :I have One class that produce multiple types of messages (notifications) and multiple consumers who consume those messages. The complication is my Producer produce different types of messages and my consumers consume those messages . So what is the best implementation of this situation? Is the Producer/Consumer design-pattern the best solution of this situation? 回答1: I think there are two independent problems

Synchronizing producer, consumer and a producer queue

时光怂恿深爱的人放手 提交于 2019-12-13 05:07:59
问题 I have a producer and a consumer. Producer fills its internal queue with objects, consumer takes these objects one by one. I want to synchronize the cosumer with the producer, so that the consumer blocks when there are no objects ready, and I want to synchronize the producer with itself, so that it stops producing when the queue is full (and starts again when there’s space). How do I do that? I was able to solve a simpler case without the queue using NSConditionalLock , but with the queue the

Producer/consumer seems to be in deadlock when buffer is smaller than input from producer

纵饮孤独 提交于 2019-12-13 04:39:58
问题 I made a circular buffer with multiple clients writing (in the end I want them to write messages of different size) into a buffer. The server reads them out. It's based on the code in a consumer/producer problem: #include <stdio.h> #include <malloc.h> #include <string.h> #include <pthread.h> #include <unistd.h> #define BUFFER_SIZE 10 struct cBuf{ char *buf; int size; int start; int end; pthread_mutex_t mutex; pthread_cond_t buffer_full; pthread_cond_t buffer_empty; }; struct cBuf cb; void buf

How do I notify a Consumer job that Producer job is done?

六月ゝ 毕业季﹏ 提交于 2019-12-13 04:17:20
问题 Using Spring/Quartz, I have an ProducerJob that is run first. Then I have a ConsumerJob that must wait for the result of ProducerJob (which creates records in the DB). What's the best way for ConsumerJob to be notified of the results of ProducerJob? Should I let ConsumerJob to constantly check the database, and sleep/wait if ProducerJob is not yet done? I realize my question may be similar to Pass BlockingQueue in JobDataMap of Quartz, although no specific implementation was identified. Still