本文整理汇总了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;
}
}
}
}
示例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();
}
}
示例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;
}
}
}
示例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";
}