Giter Site home page Giter Site logo

Comments (9)

cameron314 avatar cameron314 commented on June 2, 2024

This could occur if there's more than one thread consuming from the queue.

Also, please update to the latest master, there were some fixes around signals while blocking on the semaphore at one point.

from readerwriterqueue.

mpuskas avatar mpuskas commented on June 2, 2024

Good to know, thanks for the quick reply! We'll update to latest master and verify that we don't have multiple consumers.

from readerwriterqueue.

poor1017 avatar poor1017 commented on June 2, 2024

@cameron314 Hi, this issue is not fixed with the latest master. Can I just remove this assert directly? Thanks!

from readerwriterqueue.

cameron314 avatar cameron314 commented on June 2, 2024

No, if this assert is firing it indicates a bug somewhere, either in the queue or in the calling code. Can you share an example that reproduces?

from readerwriterqueue.

poor1017 avatar poor1017 commented on June 2, 2024

Here is the example source code:

#include <unistd.h>

#include <iostream>
#include <thread>

#include "readerwriterqueue.h"

typedef moodycamel::BlockingReaderWriterQueue<int> InputQueue;
auto input_queue = std::make_shared<InputQueue>();

void
startWorkLoop()
{
    while (true) {
        int input = 0;
        input_queue->wait_dequeue(input);
    }
}

void
startClientLoop()
{
    while (true) {
        sleep(2);
        std::cout << "enqueue ..." << std::endl;
        int input = 1;
        input_queue->enqueue(input);
    }
}

int
main(int argc, char **argv)
{
    std::shared_ptr<std::thread> thread1 = std::make_shared<std::thread>(&startWorkLoop);
    std::shared_ptr<std::thread> thread2 = std::make_shared<std::thread>(&startWorkLoop);

    std::shared_ptr<std::thread> client = std::make_shared<std::thread>(&startClientLoop);

    thread1->join();
    thread2->join();
    client->join();

    return 0;
}

Here is the CMakeLists.txt

cmake_minimum_required(VERSION 3.10.1)
project(verify)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17 -pthread -W")
set(CMAKE_BUILD_TYPE "Debug")

add_executable(main main.cc)

OS: Ubuntu 20.04

from readerwriterqueue.

cameron314 avatar cameron314 commented on June 2, 2024

You have one producer thread but two consumer threads. This is an SPSC queue (supports single consumer only).

from readerwriterqueue.

poor1017 avatar poor1017 commented on June 2, 2024

This could occur if there's more than one thread consuming from the queue.

Also, please update to the latest master, there were some fixes around signals while blocking on the semaphore at one point.

I thought this had been fixed.

B.T.W. If I want to support multiple producers multiple consumers and keep consuming in order, what should I use?

Thanks.

from readerwriterqueue.

MagicKim avatar MagicKim commented on June 2, 2024

This could occur if there's more than one thread consuming from the queue.
Also, please update to the latest master, there were some fixes around signals while blocking on the semaphore at one point.

I thought this had been fixed.

B.T.W. If I want to support multiple producers multiple consumers and keep consuming in order, what should I use?

Thanks.

Have you solved this issue? I am in a single producer and single consumer mode, and I have also encountered this error. I receive moodycamel::BlockingReaderWriterQueue enqueue from multiple network interfaces, and then wait_dequeue in a sub-thread.

from readerwriterqueue.

cameron314 avatar cameron314 commented on June 2, 2024

I thought this had been fixed.

The issue was with your example code.

B.T.W. If I want to support multiple producers multiple consumers and keep consuming in order, what should I use?

You'd need to find another queue implementation. I don't have an MPMC queue with global ordering.

I receive moodycamel::BlockingReaderWriterQueue enqueue from multiple network interfaces, and then wait_dequeue in a sub-thread.

Are you enqueueing from multiple threads?

from readerwriterqueue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.