Click here to Skip to main content
15,892,059 members
Articles / Programming Languages / C++

Windows Thread Pooling and Execution Chaining

Rate me:
Please Sign up or sign in to vote.
4.66/5 (12 votes)
26 Apr 20043 min read 125K   3.3K   75  
An article that describes a template based thread pool implementation with execution chaining
/**
 * \file		thread_pool.cpp
 * \author		Plugware Solutions.com, Ltd.
 * \date		
 * \brief		[brief here]
 *
 *              Copyright (c) 2003, 2004
 *              Plugware Solutions.com, Ltd.
 *
 *              Permission to use, copy, modify, distribute and sell 
 *              this software and its documentation for any purpose 
 *              is hereby granted without fee, provided that the above 
 *              copyright notice appear in all copies and the both that 
 *              copyright notice and this permission notice appear 
 *              in supporting documentation.  Plugware Solutions.com, Ltd. 
 *              makes no reresentations about the suitability of this 
 *              software for any purpose.  It is provided "as is" 
 *              without express or implied warranty.
 */
 
/*
**  Includes
*/

#define _WIN32_WINNT 0x0500
#include <conio.h>
#include <iostream>
#include "thread_pool.h"
using namespace plugware;

/*
**  Implementation
*/

#define WORK( label )                                           \
struct work_##label : core::work_unit                           \
{                                                               \
    void process() throw()                                      \
    {                                                           \
        std::cout << "processing work " << #label << std::endl; \
    }                                                           \
};

WORK( 1 ); 
WORK( 2 ); 
WORK( 3 );

int main(int, char**)
{
    // initialize the thread pool
    global::thread_pool::instance().initialize();    
    
    //@@todo: demonstrate asynchronous notification
    std::cout << "Press any key to die ..." << std::endl;       

    // demonstrate chaining
    global::thread_pool::instance().queue_request(
        (core::chain(), new work_1, new work_2, new work_3));

    ::getch();
    return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States

Joshua Emele lives in San Francisco. A member of
Plugware Solutions, Ltd. and specializes in network, database, and workflow applications in c++.
He is madly in love with life and his partner and enjoys teaching, playing classical guitar,
hiking, and digital electronics.



Plugware Solutions, Ltd. provides design, review, integration and implementation
consulting services and is the maker of the Plugware Web Services Platform.


Comments and Discussions