Using std::shared_ptr for each packaged_task adds unnecessary overhead. Each task submission creates a heap allocation for the shared_ptr and its control block. The lambda capture of the shared_ptr by value in write_task is necessary to keep the task alive, but this design could impact performance for high-frequency task submissions. Consider whether the shared_ptr is truly necessary or if there's a more efficient ownership model.
Using std::shared_ptr for each packaged_task adds unnecessary overhead. Each task submission creates a heap allocation for the shared_ptr and its control block. The lambda capture of the shared_ptr by value in write_task is necessary to keep the task alive, but this design could impact performance for high-frequency task submissions. Consider whether the shared_ptr is truly necessary or if there's a more efficient ownership model.