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

[REQ] cpuaff integration #113

Closed
yanzixiang opened this issue Jun 28, 2023 · 3 comments
Closed

[REQ] cpuaff integration #113

yanzixiang opened this issue Jun 28, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@yanzixiang
Copy link

cpuaff integration
the lib make all the threads private,
Is it possible to give the user the opportunity to make some modify to the threads ?
i want to make Multiple Thread Pools,
as if one pool bind to core 1,2,
and another pool bind to core 3,4,
so that i can push task to the binded core

Code example

BS::thread_pool thread_pool;

cpuaff::cpu_set new_affinity;

thread_pool.set_new_affinity(new_affinity);

Additional information

http://dcdillon.github.io/cpuaff/

#37

@yanzixiang yanzixiang added the enhancement New feature or request label Jun 28, 2023
@bshoshany
Copy link
Owner

Thanks for the feature request! One of the guiding design principles of this package is that it only uses the C++17 standard library, and does not rely on any 3rd-party and/or platform-dependent features. Unfortunately, integration with the 3rd-party package cpuaff will go against this principle, and therefore will not be implemented. However, you are welcome to start your own fork with cpuaff integration.

@yanzixiang
Copy link
Author

Thanks for the feature request! One of the guiding design principles of this package is that it only uses the C++17 standard library, and does not rely on any 3rd-party and/or platform-dependent features. Unfortunately, integration with the 3rd-party package cpuaff will go against this principle, and therefore will not be implemented. However, you are welcome to start your own fork with cpuaff integration.

there is no need to rely on any 3rd-party and/or platform-dependent features,
this feature can be done by add a callback <callback_to_config_the_thread> after creating the thread.

    /**
     * @brief A worker function to be assigned to each thread in the pool. Waits until it is notified by push_task() that a task is available, and then retrieves the task from the queue and executes it. Once the task finishes, the worker notifies wait_for_tasks() in case it is waiting.
     */
    void worker()
    {
  
       callback_to_config_the_thread()......

        while (running)
        {
            std::function<void()> task;
            std::unique_lock<std::mutex> tasks_lock(tasks_mutex);
            task_available_cv.wait(tasks_lock, [&] { return !tasks.empty() || !running; });
            if (running && !paused)
            {
                task = std::move(tasks.front());
                tasks.pop();
                tasks_lock.unlock();
                task();
                --tasks_total;
                if (waiting)
                    task_done_cv.notify_one();
            }
        }
    }

@bshoshany
Copy link
Owner

What you're asking for seems to be similar to #105, which is planned to be implemented in the next release.

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

No branches or pull requests

2 participants