Code Monkey home page Code Monkey logo

disruptor4cpp's People

Contributors

alexleemanfui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

disruptor4cpp's Issues

multi consumers issues

I have found this fantastic work and applied it to my work successfully. Everything looks great, but there is one small thing : how to create and run multiple consumers with events from multiple producers on multiple threads? because the Java version seems to support these features, so what should i do if i want to use these features.

it's bug??

modify test code,it works failed:

class int_handler : public disruptor4cpp::event_handler
{
public:
int_handler() = default;
virtual ~int_handler() = default;
virtual void on_start() { }
virtual void on_shutdown() { }
virtual void on_event(int& event, int64_t sequence, bool end_of_batch)
{
std::cout << "Received integer: " << event << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //----------modify----------
}
virtual void on_timeout(int64_t sequence) { }
virtual void on_event_exception(const std::exception& ex, int64_t sequence, int* event) { }
virtual void on_start_exception(const std::exception& ex) { }
virtual void on_shutdown_exception(const std::exception& ex) { }
};

int main(int argc, char* argv[])
{
using namespace disruptor4cpp;

// Create the ring buffer.
//ring_buffer<int, 1024, busy_spin_wait_strategy, producer_type::multi> ring_buffer;
    //----------modify----------
    ring_buffer<int, 64, busy_spin_wait_strategy, producer_type::multi> ring_buffer;

// Create and run the consumer on another thread.
auto barrier = ring_buffer.new_barrier();
int_handler handler;
batch_event_processor<decltype(ring_buffer)> processor(ring_buffer, std::move(barrier), handler);
std::thread processor_thread([&processor] { processor.run(); });

// Publish some integers.
for (int i = 0; i < 1000; i++)
{
	int64_t seq = ring_buffer.next();
	ring_buffer[seq] = i;
	ring_buffer.publish(seq);
}

// Stop the consumer.
    //----------modify----------
//std::this_thread::sleep_for(std::chrono::seconds(1));
//processor.halt();

processor_thread.join();
return 0;

}

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.