标签: queue

Erlang进程排队最佳实践?

我已经构建了一个进程队列实现,它创建了一个工作进程池,它接收带有要处理的数据的有效负载消息.完成该过程后,它会将消息发送回池中,池管理器会重新排队该进程ID以供使用.

我的问题是:放弃这个过程并产生新的过程会更好吗?还是回收它?

queue erlang process

4
推荐指数
1
解决办法
498
查看次数

是否在同步GCD队列上设置了阻止阻塞和暂停其他队列的阻塞?

我读到应该使用GCD同步队列(dispatch_sync)来实现代码的关键部分.一个例子是从帐户余额中减去交易金额的块.同步调用的有趣部分是一个问题,它如何影响多个线程上其他块的工作?

让我们假设有3个线程在异步模式下使用和执行主队列和自定义队列中的系统和用户定义块的情况.这些块都以某种顺序并行执行.现在,如果将块放在具有同步模式的自定义队列上,这是否意味着所有其他块(包括在其他线程上)都被挂起,直到块成功执行为止?或者这是否意味着只有一些锁定将被放置在该块上,而其他锁定仍将执行.但是,如果其他块使用与同步块相同的数据,那么其他块将不可避免地等到该锁将被释放.

恕我直言无所谓,是一个还是多个核心,同步模式应该冻结整个应用程序的工作.但是,这些只是我的想法所以请评论并分享您的见解:)

iphone queue sync objective-c grand-central-dispatch

4
推荐指数
1
解决办法
2234
查看次数

迭代器声明:"不包含类型"

我很难理解为什么我会收到此错误.我指的是Josuttis的STL书和其他资源,似乎我在下面声明我的迭代器的方式应该有效:

#ifndef LRU_H
#define LRU_H

#include <queue>
#include <iterator>


class LRU
{
public:

   LRU();                           // default constructor
   LRU(int);                        // constructor with argument
   ~LRU();                          // destructor 

   // Methods
   //
   void enqueue(int);               // add datum to the queue
   void dequeue();                  // remove datum from the queue
   void replace();                  // replacement algorithm
   void displayQueue() const;       // display contents of queue

private:

   // Member Data
   //
   const int MAX_SIZE;
   int m_currentCount;

   std::queue<int> m_buffer;
   std::queue<int>::const_iterator iter;

};

#endif
Run Code Online (Sandbox Code Playgroud)

但是我声明我的const_iterator的行会生成以下编译器错误:

In file included from main.cpp:10:
lru.h:41: …
Run Code Online (Sandbox Code Playgroud)

c++ queue iterator stl

4
推荐指数
1
解决办法
1084
查看次数

如何在python 3中将队列与将来的并发ThreadPoolExecutor一起使用?

我正在使用简单的线程模块来执行并发作业。现在,我想利用并发期货模块的优势。有人可以举一个使用并发库队列的例子吗?

我收到TypeError:“队列”对象不可迭代,我不知道如何迭代队列

代码段:

 def run(item):
      self.__log.info(str(item))
      return True
<queue filled here>

with concurrent.futures.ThreadPoolExecutor(max_workers = 100) as executor:
        furtureIteams = { executor.submit(run, item): item for item in list(queue)}
        for future in concurrent.futures.as_completed(furtureIteams):
            f = furtureIteams[future]
            print(f)
Run Code Online (Sandbox Code Playgroud)

python queue multithreading python-3.x concurrent.futures

4
推荐指数
1
解决办法
7078
查看次数

这个排队功能如何运作?

我无法理解这一行:

rear->next = temp;
Run Code Online (Sandbox Code Playgroud)

在这个队列函数中:

 void Queue::enqueue(int data) {

    Node *temp = new Node();    // make a temporary node
    temp->info = data;          // assign passed in data to it
    temp->next = 0;             // make it point to null

    if(front == 0)              // if there is no front node
        front = temp;           // make this a front node

    else                        // else, if there is already a front node
        rear->next = temp;      // make this rear's next pointer???? why?

    rear = temp; …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm queue data-structures

4
推荐指数
1
解决办法
2万
查看次数

python threading具有线程安全性的队列生产者 - 消费者

我正在使用线程和队列来获取URL并存储到数据库.
我只想要一个线程来做存储工作.
所以我写代码如下:

import threading
import time

import Queue

site_count = 10

fetch_thread_count = 2

site_queue = Queue.Queue()
proxy_array=[]        


class FetchThread(threading.Thread):
    def __init__(self,site_queue,proxy_array):
        threading.Thread.__init__(self)
        self.site_queue = site_queue
        self.proxy_array = proxy_array
    def run(self):
        while True:
            index = self.site_queue.get()
            self.get_proxy_one_website(index)
            self.site_queue.task_done()
    def get_proxy_one_website(self,index):
        print '{0} fetched site :{1}\n'.format(self.name,index)
        self.proxy_array.append(index)


def save():
    while True:
        if site_queue.qsize() > 0:
            if len(proxy_array) > 10:
                print 'save :{0}  to database\n'.format(proxy_array.pop())

            else:
                time.sleep(1)
        elif len(proxy_array) > 0:
            print 'save :{0} to database\n'.format(proxy_array.pop())

        elif len(proxy_array) == 0:
            print …
Run Code Online (Sandbox Code Playgroud)

python queue multithreading

4
推荐指数
1
解决办法
9477
查看次数

Python Queue.join()

即使我没有将线程设置为守护进程,一旦queue.join()完成和解除阻塞,程序是否应该退出?

#!/usr/bin/python
import Queue
import threading
import time

class workerthread(threading.Thread):
        def __init__(self,queue):
                threading.Thread.__init__(self)
                self.queue=queue
        def run(self):
                print 'In Worker Class'
                while True:
                        counter=self.queue.get()
                        print 'Going to Sleep'
                        time.sleep(counter)
                        print ' I am up!'
                        self.queue.task_done()
queue=Queue.Queue()

for i in range(10):
        worker=workerthread(queue)
        print 'Going to Thread!'
        worker.daemon=True
        worker.start()
for j in range(10):
        queue.put(j)
queue.join()
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感谢!

python queue

4
推荐指数
1
解决办法
1万
查看次数

什么是经纪人,主题,队列

我试图找到有关经纪人,主题,队列的详细信息; 但无法取得好成绩.我试图谷歌这些主题,但找不到多少.有人可以帮助解释这些概念.

queue tibco broker tibco-topic

4
推荐指数
1
解决办法
4895
查看次数

如何将张量推送到TensorFlow队列并从另一个进程中拉出它们?

我有一个TensorFlow集群启动并运行,我正在尝试使用一个客户端进程将数据入队,并将其从另一个进程出列.我不能让这个工作,我做错了什么?

这是推送数据的程序:

# queue_push.py
import tensorflow as tf
import time

with tf.container("qtest"):
    q = tf.FIFOQueue(capacity=10, dtypes=[tf.float32],
                     shapes=[[]], name="q")
    v = tf.placeholder(tf.float32, shape=())
    enqueue = q.enqueue([v])

with tf.Session("grpc://localhost:2210") as sess:
    while True:
        t = time.time()
        print(t)
        sess.run(enqueue, feed_dict={v: t})
        time.sleep(1)
Run Code Online (Sandbox Code Playgroud)

我的程序来拉数据:

# queue_pull.py
import tensorflow as tf
import time

with tf.container("qtest"):
    q = tf.FIFOQueue(capacity=10, dtypes=[tf.float32],
                     shapes=[[]], name="q")
    dequeue = q.dequeue()

with tf.Session("grpc://localhost:2222") as sess:
    while True:
        v = sess.run(dequeue)
        print("Pulled:", v)
        time.sleep(0.5)
Run Code Online (Sandbox Code Playgroud)

当我运行它们时,这就是我得到的:

$ python queue_push.py
1472420887.974484
1472420888.991067
1472420889.995756
1472420890.998365
1472420892.001799 …
Run Code Online (Sandbox Code Playgroud)

queue tensorflow

4
推荐指数
1
解决办法
863
查看次数

如何将Stream的元素收集到队列中?

我有以下代码:

Queue<Reward> possibleRewards = 
    Stream.of(Reward.values())
          .flatMap(reward -> IntStream.range(0, reward.getOccurencies()).mapToObj(i -> reward))
          .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我需要收集Stream成a 的元素Queue,而不是a List.但是,没有Collectors.toQueue()方法.如何将元素收集到Queue?

java queue lambda java-8 java-stream

4
推荐指数
1
解决办法
1601
查看次数