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


C++ thread_safe_queue::pop方法代码示例

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


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

示例1: consumer_function

//функция для потребителя(который обрабатывает данные от поставщика)
void consumer_function(int  consumerId)
{
	int number;
	while (true)
	{
		safeQueue.pop(number);
		if (number == -1)
		{
			//безопасная печать
			std::lock_guard<std::mutex> lock(printing_mutex);
			std::cout << "consumer is shutdowning" << std::endl;
			break;
		}
		else
		{
			std::lock_guard<std::mutex> lock(printing_mutex);
			if (isPrime(number) == true)
			{
				std::cout << number << " is prime" << std::endl;
			}
			else
			{
				std::cout << number << " is not prime" << std::endl;
			}
		}
	}
}
开发者ID:lenazherdeva,项目名称:MIPT-Concurrency,代码行数:28,代码来源:main.cpp

示例2: consume

void consume(thread_safe_queue<int>& tasks, mutex& writemtx, int num){
	srand((unsigned int)time(NULL));
	while (true) {
		int mod;
		tasks.pop(mod);
		writemtx.lock();
		cout <<mod <<" "<< (mod^rand()) << " " << num << "\n";	 //âîçâðàùàåò â ñòåïåíü ñëó÷àéíîãî ÷èñëà
		writemtx.unlock();
	}
}
开发者ID:veraklim,项目名称:parall_proga,代码行数:10,代码来源:thread_safe_queue.cpp

示例3: consumer

void consumer(thread_safe_queue<int> &q)
{
    int value;
    while(true)
    {
        q.pop(value);
        if (value == -1)
        {
            std::cout << "consumer quits" << std::endl;
            break;
        }
        else
        {
            std::cout << "pop: " << value << std::endl;
        }
    }
}
开发者ID:marcinklimek,项目名称:cpp_rt_2,代码行数:17,代码来源:main.cpp

示例4: isPrime

//consumer's function
void isPrime()
{
	int number = 2;
	int num_sqr;
	int counter = 0;

	try
	{
		while (true)
		{
			my_queue.pop(number);
			++counter;
			std::cout << counter << std::endl;

			if (number == 0 || number == 1)
			{
				std::cout << number << " isn't a prime number\n";
				continue;
			}

			//to stop this thread
			if (number == stop_flag) return;

			num_sqr = std::round(::sqrt(number)) + 1;

			bool is_prime = true;

			for (int check = 2; check <= num_sqr; ++check)
			{
				if (number % check == 0)
				{
					is_prime = false;
					break;
				}
			}

			(is_prime) ? (std::cout << number << " is a prime number\n") : (std::cout << number << " isn't a prime number\n");
		}
	}
	catch (std::exception & e) {
		std::cout << e.what() << std::endl;
	}
	
	std::cout << "consumer has finished his work\n";
}
开发者ID:egdeliya,项目名称:mipt_concurrency_course,代码行数:46,代码来源:main.cpp


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