Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To use one concurrent queue between multiple threads #377

Open
harshad-0302 opened this issue Mar 20, 2024 · 3 comments
Open

To use one concurrent queue between multiple threads #377

harshad-0302 opened this issue Mar 20, 2024 · 3 comments

Comments

@harshad-0302
Copy link

harshad-0302 commented Mar 20, 2024

My use case is that I have one function which will enqueue data in the queue & I have multiple threads which will dequeue & use this data at the same time one by one.

Is it possible with concurrent queue by only using single queue ?
The issue is if first thread dequeue's a data element from the queue then that data element will no more be available in the queue so how the other threads will dequeue same data element & use it?

So is there any way that only one dequeue operation happens between all the threads?

Or else any other way to resolve this using concurrent queue please suggest.

I have gone through sample examples but didn't find any example which fits my use case. So writing here, please provide your input.

@cameron314
Copy link
Owner

This is not possible with ConcurrentQueue. It's a data structure, but you seem to be searching for something closer to a messaging system.

You could, however, use N queues for N dequeueing threads, and enqueue N copies of the same data to all of them. But obviously this is suboptimal.

@harshad-0302
Copy link
Author

harshad-0302 commented Mar 21, 2024

I saw that concurrent queue supports multiple consumers so if we assume each thread to be a consumer .
Then is there any possibility that multiple consumer(threads) consume same data from the same queue?

If not then what is the exact benefit of multiple consumers ?

@cameron314
Copy link
Owner

Not possible with this data structure.

Example use: Consider a threadpool processing a series of jobs. Each thread pulls a different job from the work queue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants