Thread: Will C++ ever add a thread pool as part of its STL?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    It's just, with the advent of std::thread and lambdas, making a thread pool shouldn't be that hard to standardize, right?

    I'm not sure how it would be done but couldn't you just create a std::vector<std::thread> threadpool and then construct some number of threads with each thread listening on an unused and unique port? Then couldn't you just pass functions to the container which would then send the data to the appropriate port?

    Or is that not how it would work? I'm a super duper network newb but I read that in the most generic sense, a servers and sockets are just inter-process communications so to put a thread in a "wait" state, it should just be listening on a port for incoming data.

    Edit :
    Code:
    std::vector<std::thread> pool;
    pool.reserve(n);
    
    for (int i = 0; i < n; ++i)
    {
        pool.emplace_back([](){
            // begin listening on port blah blah blah
        });
    }
    Last edited by MutantJohn; 01-20-2015 at 06:24 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. thread pool issues
    By Elkvis in forum C++ Programming
    Replies: 1
    Last Post: 12-20-2012, 12:12 PM
  2. thread pool approach
    By fguy817817 in forum C Programming
    Replies: 3
    Last Post: 11-04-2009, 12:59 PM
  3. Thread Pool libraries or examples
    By Mastadex in forum Windows Programming
    Replies: 6
    Last Post: 08-24-2008, 08:58 PM
  4. Thread pool
    By mdoland in forum C# Programming
    Replies: 3
    Last Post: 10-19-2007, 06:41 AM
  5. Thread Pool server
    By rotis23 in forum Linux Programming
    Replies: 1
    Last Post: 02-25-2004, 08:11 AM