I would like to implement a producer/consumer scenario that obeys interfaces that are roughly:
class Consumer {
private:
vector<char> read(size_t n) {
// If the internal buffer has `n` elements, then dequeue them
// Otherwise wait for more data and try again
}
public:
void run() {
read(10);
re...
I'm reading in a lot of data from ldap which needs to be compared to the respective records in the database. To minimize the number of SQL queries, I want to batch multiple ldap records into a single query.
All this is pretty simple: A thread to produce ldap results, and a thread to consume those results and run the SQL query.
ldap_...
I would like to have a SynchronousQueue where I insert elements from one thread with put(), so the input is blocked until the element is taken in another thread.
In the other thread I perform lots of calculations and from time to time want to check if an element is already available, and consume it. But it seems that isEmpty() always re...
Sorry if I am asking same question again but want to verify!
I have two processes P1 and P2.
P1 is a writer (Producer).
P2 is a reader (Consumer).
There is some shared memory or a file that P1 writes to and as soon as P1 writes, P2 should be notified for reading.
Now as per my understanding pseudocode for P1 should be
Open shared ...
In Cocoa, I've setup two NSThreads, one producer and one consumer.
The producer appends data to an NSMutableData, and the receiver opens an NSInputStream from that data and reads in chunks.
The producer thread writes a lot faster than the consumer processes, which is OK. But the producer only produces a finite amount of work, then exits...
I have two threads. Thread A is pulling some elements from queue and thread B is adding some elements to the queue.
I want thread A to go to sleep when the queue is empty.
When thread B adds some element to the queue it should make sure that thread A is working. How can this be done in Java?
...
I recently wrote a program that used a simple producer/consumer pattern. It initially had a bug related to improper use of threading.Lock that I eventually fixed. But it made me think whether it's possible to implement producer/consumer pattern in a lockless manner.
Requirements in my case were simple:
One producer thread.
One consume...
I've got a callback method that is called whenever new data is available:
public delegate void DataCallback(
byte[] buffer,
int offset,
int count);
I want to wrap this in a class that implements an interface similar to this:
public interface IDataSource
{
IAsyncResult BeginRead(
byte[] buffer,
int offs...
I'm toying with the idea of implementing a generic Producer/Consumer pair + processing queue in C# for fun. The idea is you can just create objects that implement appropriate IProducer and IConsumer interfaces (default implementations supplied), which will consist mainly of delegates, pass them to a QueueProcessor class instance, tell i...
Hi everybody,
Let's say I have two buffers. Producer fills buffer #1, then fills
buffer #2. The consumer consumes one buffer a time, and it's very
slow. While it is consuming buffer #1, the producer is ready to fill
another buffer, but they are all full, and the consumer hasn't
finished yet with #1. So, the producer waits.
Instead of w...
I'm trying to read lines from a pipe and process them, but I'm doing something silly and I can't figure out what. The producer is going to keep producing lines indefinitely, like this:
producer.py
import time
while True:
print 'Data'
time.sleep(1)
The consumer just needs to check for lines periodically:
consumer.py
import ...
Hi guys,
I'm using ruby openid compliant library so I can be an openid consumer, I got the sample and when I try to start-up the service, it show errors like
/var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/session/cookie_store.rb:163:in `ensure_session_key': A key is required to write a cookie containing the session data...
I'm using a single producer-single consumer model with a blocking queue. I would like for the producer, when it has finished producing, to wait for the queue to empty before returning.
I implemented the BlockingQueue suggested here by Marc Gravell.
In my model, the producer (renderer) is using events to notify the worker (printer) whe...
I have simple one producer two consumers code as follow
but the output are only C2 consuming.
any bug in my code?
class Program
{
static void Main(string[] args)
{
Object lockObj = new object();
Queue<string> queue = new Queue<string>();
Producer p = new Producer(queue, lockObj);
Comsumer c1 =...
I'm writing an application that has a multiple producer, single consumer model (multiple threads send messages to a single file writer thread).
Each producer thread contains two queues, one to write into, and one for a consumer to read out of. Every loop of the consumer thread, it iterates through each producer and lock that producer...
I am attempting a multiple producer/consumer problem in C, but its not working as expected. The following is some pseudo code to represent my implementation.
Thread thread1;
Thread thread2;
Thread thread3;
Data data1;
Mutex data1_mutex;
Semaphore data1_empty;
Semaphore data1_fill;
Data data2;
Mutex data2_mutex;
Semaphore data2_empty;
...
I have a scenario where Multiple Producers are running on different machines in a Network. These are Singleton WCF Services which are queuing the Products (Output) in the Central Store which is also a Singleton WCF Service.
There are consumers who dequeue the product from the Central Store by calling the Central Store via a JSON Request...
We have a web-application that lets the users trigger a request to an external resource. The external resource spends an unspecified amount of time to gather results, so we have to poll it to get updates, and to collect the final results when they are done.
We wish to make it so that when the user triggers the request, it gets added to ...
I've got a producer and a consumer. The producer writes fixed size items on a given shared memory area, and the consumer retrieves them.
The producer can be noticeably slower or faster than the consumer, randomly.
What we want is that
If the producer is running faster than the consumer, when it fills the circular buffer, it keeps wri...
Hi,
I was reading up on ActiveMQ which seems like a great implementation of a servicebus where producers can post messages and other processes can receive them.
However when reading the documentation, it looks like the producer has to give the 'endpoint' when sending a message.
I would rather have it the other way around: My producer ...