CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 1 of 1

Thread: Using a thread pool in real situations

  1. #1
    Join Date
    Jan 2009

    Using a thread pool in real situations

    If I need to improve an existing code by using a thread pool, how can I get data from a SQL DB:

    bool CMyClass::GetSQLSelect(std::string sql, void* data)
    and suppose I have another code, higher level:

    void CMyClass::DoSomething()
    	void* data = nullptr;
    	if (!GetSQLSelect("SELECT * FROM my_table", data))
    	std::string result = static_cast<std::string>(data);
    	// do something with result
    Now, all examples from internet give me some examples of how to add some methods to a thread pool, but those methods are not returning data to the main thread. What if I need data from those posted to thread methods ?

    I have found and example right here:

    I have seen something very simple using boost:

    void my_task() { ... }
    int main()
    	int threadNumbers = thread::hardware_concurrency();
    	boost::asio::thread_pool pool(threadNumbers);
    	// Submit a function to the pool.
    	boost::asio::post(pool, my_task);
    	// Submit a lambda object to the pool.
    	boost::asio::post(pool, []() {
    but how can I use it in my case, when I expect data from posted method ? Something like that:

    std::string sql = "SELECT * from my_table";
    void* data = nullptr;
    boost::asio::post(GetSQLSelect, sql, data);
    but when I retrieve data then ?

    Every hint, even small one, I will appreciate it most !
    Last edited by mesajflaviu; April 19th, 2021 at 03:44 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)