This article mainly describes the Python simulation to implement the producer consumer model of the relevant data, where the use of thread knowledge, queue knowledge and recycling knowledge, the need for friends can refer to the next
A detailed example of how Python simulation implements the producer consumer model
The use of python3.4 simulation to achieve a producer
1. Background
Recently, due to project requirements, Kafka's producer needs to be used. However, for C ++, Kafka is not officially supported.
On the official Kafka website, you can find the 0.8.x client. The client that can be used has a C-version client. Although the client is still active, there are still many code problems and the support for C ++ is not very good.
There is also the C ++ version. Altho
Recently reviewed the thread, found running consumer and producer code parts, there will always be first consumption after production.
The source code is as follows:
public class Producerconsumer {public static void main (string[] args) {syncstack ss = new Syncsta
CK ();
Producer p = new
enter the object, only the thread that obtains the object key can access the synchronization method. Other threads wait in the object until the thread uses the wait () method to discard the key, other threads waiting to seize the key can be executed only after the thread that grabs the key is obtained. threads without obtaining the key are still blocked and waiting in the object. All in all, synchonized enables only one thread to enter the critical code
I. Description of the problem
The problem of producer consumers is a typical thread synchronization problem. Producers of goods placed in containers, containers have a certain capacity (can only be put in order, first put after the take), consumer goods, when the container is full, producers wait, when the container is empty, consumers wait. When the producer puts the goods into the container, informs the
solve complex synchronization problems.
You can assume that the condition object maintains a lock (Lock/rlock) and a waiting pool. The thread obtains the condition object through acquire, and when the wait method is called, the thread releases the lock inside the condition and enters the blocked state (but does not actually block the current thread) and records the thread in the waiting pool at the same time. When the Notify method is called, the condition object picks a thread from the waiting
Sample code:
Copy Code code as follows:
require "thread"
puts "Proandcon"
Queue = Qu eue.new #用队列Queue实现线程同步
producer = thread.new do
NBSP;NBSP;NB Sp 10.times do |i|
sleeping rand (i) # Let threads sleep for a period of time
NBSP;NBSP ; queue puts #{i} Produced '
Ruby uses threads to implement typical producer and consumer problem code instances.
Sample Code:
Copy codeThe Code is as follows:Require "thread"Puts "ProAndCon"Queue = Queue. new # Use the Queue queue for Thread SynchronizationProducer = Thread. new do10. times do | I |Sleep rand (I) # Let the thread sleep for a peri
(interruptedexception E1) { - e1.printstacktrace (); Wu } - } AboutE e = list.get (0); $List.remove (0); -System.out.println (Thread.CurrentThread (). GetName () + "consumer Products"); - Try { -Thread.Sleep (1000); A}Catch(interruptedexception E1) { + e1.printstacktrace (); the } - List.notifyall (); $ returne; the } the } the the /** - * Determine if the current warehouse is empty in * the * @return the
This article mainly introduces Ruby to realize producer and consumer code sharing, this article directly gives the implementation code, the need for friends can refer to the following
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21-22
#ruby实现生产者和消费者代码 require ' thread ' queue = queue.new consumers = thread.new do 5.times do |i| obj = que
Example code for generating bar chart (Bar Chart) effects using html5, html5 bar chartCopy XML/HTML Code to clipboard
Code for generating a bar chart (
WOFF is a web font format recommended by W3C of the World Wide Web alliance. It is compatible with the latest Internet Explorer, Firefox, Google, apple, Opera, and many other browsers. Webpage fonts allow website-related personnel to build website-based applications, such as bar code, MICR, and OCR, without installing fonts on terminal machines. BecauseBar Code f
Bar Code problem dp + Method for Finding the serial number of a sequence in a certain arrangement, bar code dp
Question
A Bar code is a symbol that appears alternately between a Light Bar
ERP bar code solution, Kingdee disc machine bar code solution, and application of PDA information management can bring about changes to our production management.
Currently, more and more Chinese enterprises, large and small, have accepted the idea of ERP. Most stores, enterprises, and factories use an ERP software fo
The real purpose of loading animations and progress bars is to let users know the task progress. There are many JavaScript-based animations, but I decided to switch to css3.In this tutorial, I decided to make an animation progress bar using pure CSS: no flash, no images, no scripts. He can dynamically load changesIn addition, I focus on finding the simplest way to do this.Here is an example:
These
Article Maybe you like it too
Cutting-edge design
Vue2 scroll bar loads more data implementation code, vue2 scroll bar loads code
Resolution:
To judge the scroll bar to the bottom, three DOM attribute values are required, namely scrollTop, clientHeight, and scrollHeight.
ScrollTop indicates the scroll distance of the scroll
The progress bar changes with the progress. ios source code and progress bar ios source code
This is a case of changing the progress bar with the progress. The progress bar of EAColourfulProgressView and EAColourfulProgressView c
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.