当前位置: 首页>>代码示例>>C++>>正文


C++ concurrent_queue::push方法代码示例

本文整理汇总了C++中concurrent_queue::push方法的典型用法代码示例。如果您正苦于以下问题:C++ concurrent_queue::push方法的具体用法?C++ concurrent_queue::push怎么用?C++ concurrent_queue::push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在concurrent_queue的用法示例。


在下文中一共展示了concurrent_queue::push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: child

void child() {
    for (int i=1; i<=max_num; i++) {
        cq.push(i);
    }
    // Queue is closed only if all child threads are finished
    if(bar.wait()) cq.close();
}
开发者ID:windoze,项目名称:boost.green_thread,代码行数:7,代码来源:test_cq.cpp

示例2:

 //! executing filter
 /*override*/ void* operator()(void*)
 {
     int n = --N;
     if(n <= 0) return 0;
     Queue.push( Matrix1110 );
     return &Queue;
 }
开发者ID:GDXN,项目名称:fitsliberator,代码行数:8,代码来源:Fibonacci.cpp

示例3: main

int main()
{
    srand(time(0));

    // Custom scheduling is not required - can be integrated
    // to other systems transparently
    main_tasks.push([]
    {
        asynchronous([]
        {
            return async_user_handler(),
                   finished = true;
        });
    });

    Task task;
    while(!finished)
    {
        main_tasks.pop(task);
        task();
    }

    cout << "Done" << std::endl;

    return EXIT_SUCCESS;
}
开发者ID:ElaraFX,项目名称:boost,代码行数:26,代码来源:await_emu.cpp

示例4: ccr_worker

static void* ccr_worker(void *arg)
{
    int r, resume;
    process_t *proc;
    while (1)
    {
        // Checks if threads need to be killed and the the ready procces's queue is empty
        // That way only when the queue is empty the threads are killed
        // if ((free_flag.compare_and_swap(false, true)) && (prc_ready.empty()))
        if (free_flag.compare_and_swap(false, true))
        {
            pthread_t thread = pthread_self();
            // removes reference from the pool
            thr_pool.remove(thread);

            // checks if threre's more threads to kill and set the flag
            if (free_workers.fetch_and_decrement() > 1)
            {
                free_flag.compare_and_swap(true, false);
            }

            //kills the current thread
            pthread_exit(NULL);
        }
        prc_ready.pop(proc);
        if (!proc) return NULL;
        r = lua_resume(proc->L, 0);
        switch (r)
        {
            case  LUA_YIELD:
                //cerr << "Yield!\n";
                switch (proc->status)
                {
                    case PS_READY:
                        // releasing the lock acquired in ccr_yield
                        proc->wlock.release();
                        prc_ready.push(proc);
                        break;
                    case PS_BLOCKING:
                        proc->status = PS_BLOCKED;
                        // releasing the lock acquired in ccr_yield
                        proc->wlock.release();
                        break;
                }
                break;
            case LUA_ERRRUN:
            case LUA_ERRMEM:
            case LUA_ERRERR:
                cerr << "[ERROR][PROCESSING A LUA PROCESS] " << lua_tostring(proc->L, -1) << endl;
                // fall-through
            case 0:
                lua_close(proc->L);
                mbx_close(proc->mbox);
                prc_free(proc);
                break;
        }
    }
    return NULL;
}
开发者ID:DaiYamatta,项目名称:ALua,代码行数:59,代码来源:ccr.cpp

示例5: producer

void producer(std::atomic<bool>& keep_working, concurrent_queue<std::vector<char> >& sink)
{
    while (keep_working.load())
    {
        if (sink.size() > 10000)
            std::this_thread::yield();
        else
            sink.push(std::vector<char>(rand() % 10000));
    }
}
开发者ID:sorokin,项目名称:malloc-testing,代码行数:10,代码来源:main.cpp

示例6: pop_if_present

 //! Get pair of matricies if present
 bool pop_if_present( pair<Matrix2x2, Matrix2x2> &mm ) {
     // get first matrix if present
     if(!Queue.pop_if_present(mm.first)) return false;
     // get second matrix if present
     if(!Queue.pop_if_present(mm.second)) {
         // if not, then push back first matrix
         Queue.push(mm.first); return false;
     }
     return true;
 }
开发者ID:GDXN,项目名称:fitsliberator,代码行数:11,代码来源:Fibonacci.cpp

示例7: operator

    void operator() (const blocked_range<size_t>&r) const
    {
        size_t begin = r.begin();
        size_t end = r.end();

        for (size_t i = begin; i < end; i++) {
            void * tmp = tbballoc.allocate(1);
            memset(tmp, 1, objsize);
            cq.push(tmp);
        }
    }
开发者ID:Agobin,项目名称:chapel,代码行数:11,代码来源:time_tbbq_sizes.cpp

示例8: main

int main(int argc, char*argv[])
{
    size_t nElements = 1280000;
    size_t nthreads = 1;
    struct timeval start, stop;

    if (argc >= 2) {
        nthreads = atoi(argv[1]);
    }
    if (argc >= 3) {
        nElements = atoi(argv[2]);
    }
    if (argc >= 4) {
        objsize = atoi(argv[3]);
    }

    task_scheduler_init init(nthreads);

    for (uintptr_t i = 0; i < nElements; i++) {
        cq.push((void*)i);
    }
    for (uintptr_t i = 0; i < nElements; i++) {
        void* j;
        cq.try_pop(j);
        assert(i == (uintptr_t)j);
    }
    assert(cq.empty());

    tick_count t0 = tick_count::now();
    parallel_for(blocked_range<size_t>(0, nElements), loop_queuer());
    tick_count t1 = tick_count::now();
    printf("queue time: %f secs\n", (t1 - t0).seconds());

    t0 = tick_count::now();
    parallel_for(blocked_range<size_t>(0, nElements), loop_dequeuer());
    t1 = tick_count::now();
    printf("dequeue time: %f secs\n", (t1 - t0).seconds());

    assert(cq.empty());

    t0 = tick_count::now();
    parallel_for(blocked_range<size_t>(0, nElements), loop_queuer());
    parallel_for(blocked_range<size_t>(0, nElements), loop_dequeuer());
    t1 = tick_count::now();
    printf("both time: %f secs\n", (t1 - t0).seconds());

    assert(cq.empty());

    printf("success!\n");
    return 0;
}
开发者ID:Agobin,项目名称:chapel,代码行数:51,代码来源:time_tbbq_sizes.cpp

示例9: ccr_rawsend

int ccr_rawsend(process_t *proc, message_t *msg)
{
    queuing_rw_mutex::scoped_lock rlock;
    rlock.acquire(proc->lock, false);
    if (mbx_put(proc->mbox, msg))
    {
        if (proc->status.compare_and_swap(PS_READY, PS_BLOCKED) == PS_BLOCKED)
            prc_ready.push(proc);
        rlock.release();
        return 1;
    }
    rlock.release();
    return 0;
}
开发者ID:DaiYamatta,项目名称:ALua,代码行数:14,代码来源:ccr.cpp

示例10: ccr_finalize

static int ccr_finalize(lua_State *L)
{
    int i;
    process_t *proc;
    lua_getfield(L, LUA_REGISTRYINDEX, CCR_SELF);
    proc = (process_t*)lua_touserdata(L, -1);
    if (proc->main)
    {
        for (i = 0; i < THR_SIZE; i++)
        {
            prc_ready.push(NULL);
        }

        for (list<pthread_t>::iterator thread = thr_pool.begin(); thread!=thr_pool.end(); ++thread)
        {
            pthread_join(*thread, NULL);
        }
    }
    return 0;
}
开发者ID:DaiYamatta,项目名称:ALua,代码行数:20,代码来源:ccr.cpp

示例11: ccr_spawn

static int ccr_spawn(lua_State *L)
{
    process_t *proc;
    const char *str = luaL_checkstring(L, 1);
    proc = new process_t();
    if (proc)
    {
        proc->main = 0;
        proc->counter = 1;
        proc->status = PS_READY;
        proc->mbox = mbx_create();
        if (proc->mbox)
        {
            proc->L = luaL_newstate();
            if (proc->L)
            {
                // luaL_openlibs(proc->L);
                ccr_openlibs(proc->L);
                lua_pushstring(proc->L, CCR_SELF);
                lua_pushlightuserdata(proc->L, proc);
                lua_rawset(proc->L, LUA_REGISTRYINDEX);
                if (!luaL_loadstring(proc->L, str))
                {
                    prc_ready.push(proc);
                    lua_pushboolean(L, 1);
                    return 1;
                }
                cerr << "[ERROR][CREATING LUA PROCESS] " << lua_tostring(proc->L, -1) << endl;
                lua_close(proc->L);
            }
            mbx_free(proc->mbox);
        }
        delete proc;
    }
    lua_pushboolean(L, 0);
    return 1;
}
开发者ID:DaiYamatta,项目名称:ALua,代码行数:37,代码来源:ccr.cpp

示例12: comm_request_cs

int comm_request_cs( unsigned int group ) {
  int error = 0;

  // Check to see if the reply is for a group that exists if not skip
  group_map_t::iterator group_it = comm_groups.find( group );
  if ( group_it == comm_groups.end() ) {
  cout << "comm_request_cs Cannot request critical section for group " << group << endl;
    error = -1;
    return error;
  }
  
  // Request critical section for specified group. Record stats for waiting time
  cs_entry_t req;
  req.seq_num = 0;
  req.wait_time = 0;
  req.msg_count = 0;
  CStopWatch timer;
  msg_t      outgoing;
  outgoing.send_ID  = NODE_INFO.id;
  outgoing.dest_ID  = 0;
  outgoing.ts       = comm_seq_num.num;
  outgoing.group_ID = group;
  outgoing.msg_type = MSG_T_REQUEST_CS;
  
  timer.startTimer();
  
  // Lock cs entries so they don't change while reading
  // comm_seq_num.mutex.lock();
  // group_it->second.cs.mutex.lock();
  SHARED_VARS.lock();
  
  group_it->second.cs.requesting = true;
  
  // Update and record sequence numbers
  comm_seq_num.num = comm_seq_num.max_num + 1;
  outgoing.ts = comm_seq_num.num;
  req.seq_num = comm_seq_num.num;  
  
  for ( map<unsigned int, critical_section_t>::iterator it = group_it->second.cs.cs_map.begin();
        it != group_it->second.cs.cs_map.end();
        it++ ) {
    if ( !(it->second.mutex_token) ) {
      req.msg_count++;
      outgoing.dest_ID = it->first;
      comm_send( outgoing );
    }
  }
  
  // Total messages exchanged is always 1 sent + 1 recv = 2*sent
  req.msg_count *= 2;
  
  // group_it->second.cs.mutex.unlock();  
  // comm_seq_num.mutex.unlock();
  SHARED_VARS.unlock();
 
  // If no requests were made, do not wait on any replies
  if ( req.msg_count > 0 ) {
    group_it->second.cs.entry_ok.wait( group_it->second.cs.entry_ok_mutex );
  }
 
  // Record wait time
  timer.stopTimer();
  req.wait_time = timer.getElapsedTime();

  cout << "cs log entry: " << "seq_num " << req.seq_num
       << " wait_time = " << req.wait_time
       << " msg_count = " << req.msg_count << endl;

  comm_cs_log.push( req );
  
  return 0;
}
开发者ID:Siddharthsas07,项目名称:utd,代码行数:72,代码来源:communication_server.cpp

示例13: main

int main()
{
    try
    {
        dExternalDustCurrentOffset = DUST_OFFSET_INIT_VALUE ;
        dExternalDustCurrentMinValue = DUST_MIN_INIT_VALUE ;
        bContinueExecution = true ;

        // Registriamo il segnale interrupt Software del S.O. scatenato con il CTRL+C  e l'handler da evocare a fronte del suo
        // "lancio" da parte del S.O. stesso
        signal( SIGINT , Signal_Callback_Handler ) ;

        // Crea il thread che "consuma" i valori rilevati dai sensori
        thread threadConsumatore( ( CConsumaValoriSensori() ) ) ;
        // Detach perche' la sua esecuzione puo' viaggiare indipendente e noi non dobbiamo conoscerne lo stato
        threadConsumatore.detach() ;

        // Crea il thread per la lettura del sensore I2C interno
        // async per poterne facilmente attendere la chiusura prima del return del main, se si esce con CTRL+C
        future<void> threadI2C = async( launch::async , CReadI2C() ) ;

        // Crea il thread che "tara" i valori rilevati dal sensore delle polveri
        thread threadTaraPolveri( ( CTaratoreValoriPolveri() ) ) ;
        // Detach perche' la sua esecuzione puo' viaggiare indipendente e noi non dobbiamo conoscerne lo stato
        threadTaraPolveri.detach() ;

        CUsbUtils usbUtils ;
        unsigned char pReadBuffer[6] = { 0 , 0 , 0 , 0 , 0 , 0 } ;

        uint16_t nsReadCounter = 0 ;
        /*
        * Misuriamo le polveri ogni 10 ms e temperatura ed umidita' ogni 1000 ms
        */
        while ( bContinueExecution )
        {
            try
            {
                nsReadCounter++ ;

                int nReadedBytes = 0 ;

                if ( usbUtils.Read( pReadBuffer , 6 , &nReadedBytes ) )
                {
                    // Elaborazione della lettura delle polveri
                    uint16_t nsDust = ( pReadBuffer[0] << 8 ) + pReadBuffer[1] ;

                    externalDustMeasurements.push( CUtils::FormatDustValue( nsDust ) ) ;

                    // Se abbiamo raggiunto il valore HUMIDITY_AND_TEMPERATURE_PERIOD_COUNTER del contatore, significa che siamo pronti per
                    // processare anche temperatura ed umidita', oltre alla polvere
		    if ( nsReadCounter == HUMIDITY_AND_TEMPERATURE_PERIOD_COUNTER )
                    {
                        // Elaborazione della lettura della temperatura e dell'umidita' (esterne)
                        uint16_t nsHumidity = ( pReadBuffer[2] << 8 ) + pReadBuffer[3] ;
                        uint16_t nsTemperature = ( pReadBuffer[4] << 8 ) + pReadBuffer[5] ;
					
                        if ( nsHumidity == HUMIDITY_AND_TEMPERATURE_ERR_CODE || nsTemperature == HUMIDITY_AND_TEMPERATURE_ERR_CODE )
                        {
                            CUtils::AddWarningMessage( "Errore nel Sensore di Temperatura e Umidita' del PIC" ) ; 
                        }
                        else 
                        {
                            double dExternalTemperatureCelsius = CUtils::FormatTemperatureValue( nsTemperature ) ;
                            double dExternalHumidityPercentage = CUtils::FormatHumidityValue( nsHumidity ) ;
                            //cout << "Temperatura: " << dExternalTemperatureCelsius ;
                            //cout << " Umidita': " << dExternalHumidityPercentage << endl ;

                            // Aggiungo i valori di temperatura ed umidita'
                            t_HumidityAndTemperatureMeasurementData humidityAndTemperatureMeasurementData ;
                            humidityAndTemperatureMeasurementData.m_dHumidityPercentage = dExternalHumidityPercentage ;
                            humidityAndTemperatureMeasurementData.m_dTemperatureCelsius = dExternalTemperatureCelsius ;
                            externalHumidityAndTemperatureMeasurements.push( humidityAndTemperatureMeasurementData ) ;
                        }

                        nsReadCounter = 0 ;
                    }
                }
                else
                {
                    CUtils::AddWarningMessage( string( "main - usbUtils.Read fallita. VID Device: " ) + to_string( PIC_VID ) + string( " PID Device: " ) + to_string( PIC_PID ) ) ;
                }

                std::chrono::milliseconds sleep_duration( DUST_MEASUREMENT_PERIOD_MS ) ;
                std::this_thread::sleep_for( sleep_duration ) ;
            }
            catch( const exception& e )
            {
                CUtils::AddWarningMessage( "main - Eccezione durante la lettura dei dati dai sensori. Testo: " + string( e.what() ) ) ;
            }
        }

        threadI2C.wait() ;
    }
    catch( const exception& e )
    {
        CUtils::AddWarningMessage( "main - Eccezione generica. Testo: " + string( e.what() ) ) ;
    }

    return 0 ;
}
开发者ID:AlessioVallero,项目名称:RaspberryPI,代码行数:100,代码来源:Main.cpp

示例14: main


//.........这里部分代码省略.........
	ValuePlot plot_absdiff("plot absdiff", 640, 360, 0, 640, -4, 0, 1);
	plot_absdiff.use_vmap = true;
	plot_absdiff.vmap = [](float v) { return log10(v); };
	
	ValuePlot plot_dev("plot dev", 640, 360, 0, 640, -4, 0);
	plot_dev.use_vmap = true;
	plot_dev.vmap = [](float v) { return log10(v); };

	cv::Mat diff(height, width, CV_32F, cv::Scalar::all(0.0f));
	cv::Mat absdiff(height, width, CV_32F, cv::Scalar::all(0.0f));
	cv::Mat viewdiff(height, width, CV_32F, cv::Scalar::all(0.0f));
	cv::Mat mask(height, width, CV_8U, cv::Scalar::all(0));

	std::thread reader(readfn, vid);
	std::thread writer(writefn, outaudio, outdiff);

#ifdef WIN32
	SetThreadPriority(writer.native_handle(), THREAD_PRIORITY_ABOVE_NORMAL);
#endif

	double sched = hrtimer();
	double dsched = 0.25;

	double statsched = hrtimer();
	double dstat = 1.0;
	double encode_fps = 0.0;
	double encode_alpha = 0.1;
	unsigned lastcount = 0, dcount = 0;

	// DEBUG
	//dstat = 0.0;

	for (int k = 0; k < 5; k += 1)
		donequeue.push(true);

	while (running)
	{
		MatOrNothing item;
		bool success = framequeue.try_pop(item);
		if (!success)
			continue;
		if (!item.anything)
			break;

		// FIXME: compensate for sporadic *fast* whole-image luminance fluctuations (not caught by sigma)
		
		donequeue.push(true);

		frame = item.frame;
		gray = item.gray;
		unsigned frameno = item.frameno;

		if (use_inmask)
			cv::subtract(gray, average, diff, inmask);
		else
			cv::subtract(gray, average, diff);

		cv::add(diff, 0.5, viewdiff);
		absdiff = cv::abs(diff);
		auto diffsum = (cv::sum(absdiff)[0] / (width * height));

		// =====================================================================
		// TODO: histogram: deviation from 'average', bin size = 0.1, -10..+10, y-log

		/*
		a_avg.push_back(cv::sum(diff)[0] / (double)(width * height));
开发者ID:crackwitz,项目名称:foreground,代码行数:67,代码来源:foreground.cpp

示例15: readfn

void readfn(cv::VideoCapture *vid)
{
	int frameno = (int)vid->get(CV_CAP_PROP_POS_FRAMES);
	int const width = (int)vid->get(CV_CAP_PROP_FRAME_WIDTH);
	int const height = (int)vid->get(CV_CAP_PROP_FRAME_HEIGHT);

	cv::Mat blendedframe, curframe;
	cv::Mat floatframe;
	cv::Mat grayframe;

	blendedframe.create(cv::Size(width, height), CV_16UC3);

	while (running)
	{
		if (!vid->grab())
			break;

		bool do_process = true;

		if (blendframes)
		{
			vid->retrieve(curframe);
			//curframe.convertTo(curframe, CV_16UC3);

			/*
			std::ostringstream label;
			label << "Frame " << frameno;
			cv::putText(curframe, label.str(), cv::Point(10, 20 * (frameno % 50)), cv::FONT_HERSHEY_PLAIN, 2, cv::Scalar::all(255), 2);
			//*/

			//std::cerr << "%reduction = " << (frameno % reduction) << std::endl;

			if (frameno % reduction == 0)
				blendedframe.setTo(0);

			//blendedframe = cv::max(blendedframe, curframe);
			cv::add(blendedframe, curframe, blendedframe, cv::noArray(), CV_16UC3);

			if (frameno % reduction == reduction - 1)
				blendedframe.convertTo(floatframe, CV_32FC3, 1.0 / (reduction * 255));
			else
				do_process = false;



			/*
			cv::Mat foo;
			cv::resize(blendedframe, foo, cv::Size(640, 360));
			cv::imshow("debug", foo);
			if (cv::waitKey(100) != -1) exit(0);
			//*/

			//std::cerr << "do_process = " << (do_process) << std::endl;

		}
		else
		{
			if (frameno % reduction == reduction - 1)
			{
				vid->retrieve(curframe);
				curframe.convertTo(floatframe, CV_32FC3, 1.0 / 255);
			}
			else
			{
				do_process = false;
			}

		}

		frameno += 1;

		if (!do_process)
			continue;

		// TODO: proper bounded queue...
		while (running)
		{
			bool foo;
			bool res = donequeue.try_pop(foo);
			if (res)
				break;
		}

		// frameu8 is ready
		cv::cvtColor(floatframe, grayframe, CV_BGR2GRAY, 1);
		cv::blur(grayframe, grayframe, blur);

		MatOrNothing const tmp = { true, floatframe.clone(), grayframe.clone(), frameno };
		framequeue.push(tmp);
		//std::cout << "pushing frame " << frameno << std::endl;
	}

	MatOrNothing const tmp = { false };
	framequeue.push(tmp);
}
开发者ID:crackwitz,项目名称:foreground,代码行数:95,代码来源:foreground.cpp


注:本文中的concurrent_queue::push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。