//! @brief デストラクタ
    //! @detail デストラクタは、スレッドの終了を待機するが、
    //! その際にwait_before_destructed()がtrueの場合、
    //! キューに積まれたタスクが全て実行され、すべての実行が完了してからスレッドを終了する。
    //! falseの場合、キューに積まれたままのタスクは実行されず、
    //! 呼び出し時点で取り出されているタスクのみ実行してスレッドを終了する。
    //! @note wait_before_destructed()はデフォルトでtrue
    ~task_queue_with_allocator()
    {
        if(wait_before_destructed()) {
            wait();
        }

		set_terminate_flag(true);
		//! Add dummy task to wake all threads,
		//! so the threads check terminate flag and terminate itself.
		for(size_t i = 0; i < num_threads(); ++i) {
			enqueue([]{});
		}

        join_threads();
    }
Exemple #2
0
void        
xct_t::vtable_collect(vtable_row_t &t)
{
    // xct_nthreads_attr
    t.set_int(xct_nthreads_attr, num_threads());

    // xct_gtid_attr
    if(is_extern2pc()) {
        w_ostrstream        s;
        s << *gtid() << ends;
        t.set_string(xct_gtid_attr, s.c_str());
    } else {
        t.set_string(xct_gtid_attr, "");
    }
    // xct_tid_attr
    {
        w_ostrstream o;
        o << tid() << ends;
        t.set_string(xct_tid_attr, o.c_str());
    }

    // xct_state_attr
    {
        w_ostrstream o;
        o << state() << ends;
        t.set_string(xct_state_attr, o.c_str());
    }

    // xct_coordinator_attr
    if(state() == xct_prepared) {
        w_ostrstream        s;
        s << get_coordinator() << ends;
        t.set_string(xct_coordinator_attr, s.c_str());
    } else {
        t.set_string(xct_coordinator_attr, "");
    }

    // xct_forced_readonly_attr
    t.set_string(xct_forced_readonly_attr, 
            (forced_readonly()?"true":"false"));
}
Exemple #3
0
static void submit_fullfile_tasks(GList *files)
{
	GThreadPool *threadpool;
	GList *item;
	struct file *file;
	int ret;
	int count = 0;
	GError *err = NULL;
	int numthreads = num_threads(3.0);

	LOG(NULL, "fullfile threadpool", "%d threads", numthreads);
	threadpool = g_thread_pool_new(create_fullfile_task, NULL,
				       numthreads,
				       TRUE, NULL);

	printf("Starting downloadable fullfiles data creation\n");

	item = g_list_first(files);
	while (item) {
		file = item->data;
		item = g_list_next(item);

		/* do not push ghosted files */
		if (file->is_ghosted) {
			continue;
		}

		ret = g_thread_pool_push(threadpool, file, &err);
		if (ret == FALSE) {
			printf("GThread create_fullfile_task push error\n");
			printf("%s\n", err->message);
			assert(0);
		}
		count++;
	}
	printf("queued %i full file creations\n", count);

	printf("Waiting for downloadable fullfiles data creation to finish\n");
	g_thread_pool_free(threadpool, FALSE, TRUE);
}
Exemple #4
0
int
main( int argc, char **argv )
{
    const static auto chunksize( 65536 );
    using chunk_t = raft::filechunk< chunksize >;
    using fr_t    = raft::filereader< chunk_t, false >;
    using fw_t    = filewrite< chunk_t >;
    using comp    = compress< chunk_t >;
   
    /** variables to set below **/
    bool help( false );
    int blocksize ( 9 );
    int verbosity ( 0 );
    int workfactor( 250 );
    std::string inputfile( "" );
    std::string outputfile( "" );
    
    std::int64_t  num_threads( 1 );

    CmdArgs cmdargs( argv[ 0 ] /** prog name  **/,
                     std::cout /** std stream **/,
                     std::cerr /** err stream **/ );

    /** set options **/
    cmdargs.addOption( new Option< bool >( help,
                                           "-h",
                                           "print this message" ) );
    cmdargs.addOption( new Option< int >( blocksize,
                                          "-b",
                                          "set block size to 100k .. 900k" ) );
    cmdargs.addOption( new Option< int >( workfactor,
                                          "-e",
                                          "effort" ) );
    cmdargs.addOption( new Option< std::string >( inputfile,
                                                  "-i",
                                                  "input file",
                                                  true /** required **/ ) );

    cmdargs.addOption( new Option< std::string >( outputfile,
                                                  "-o",
                                                  "output file",
                                                  true /** required **/ ) );
    
    cmdargs.addOption( new Option< std::int64_t  >( num_threads,
                                                    "-th",
                                                    "number of worker threads" ) );
    
    /** process args **/                                                  
    cmdargs.processArgs( argc, argv );
    if( help || ! cmdargs.allMandatorySet() )
    {
        cmdargs.printArgs();
        exit( EXIT_SUCCESS );
    }

    /** declare kernels **/
    fr_t reader( inputfile,
                 num_threads /** manually set threads for b-marking **/ );
    fw_t writer( outputfile, 
                 num_threads /** manually set threads for b-marking **/ );
    comp c( blocksize, 
            verbosity, 
            workfactor );
    
    /** set-up map **/
    raft::map m;
    
    /** 
     * detect # output ports from reader,
     * duplicate c that #, assign each 
     * output port to the input ports in 
     * writer
     */
    m += reader <= c >= writer;

    m.exe();
    return( EXIT_SUCCESS );
}