Valar Morghulis
Valar Morghulis

Reputation: 107

What's the difference between asio::io_context and asio::thread_pool?

Whats the difference between an asio::thread_pool and an asio::io_context whose run() function is called from multiple threads? Can I replace my boost::thread_group of threads that call io_context::run() with an asio::thread_pool? Or do I need somewhere an io_context?

Update

When I use asio::thread_pool, do I still need an io_context to use sockets, timers, etc? Both thread_pool and io_context are an asio::execution_context. However, the docs say on io_context that it "Provides core I/O functionality". Do I lose these if I only use an asio::thread_pool without an io_context?

Upvotes: 8

Views: 3217

Answers (1)

sehe
sehe

Reputation: 393064

A threadpool implicit runs all the tasks posted on it (until it's stopped).

An io_service doesn't assume anything about the threads that will run it: you need to make sure you do that, and you're free to decide whether you run it on multiple threads, one thread, or even a mix (like one thread at at time, but from multiple threads?).

Further notes:

Upvotes: 9

Related Questions