更推荐使用:http://www.boost.org/doc/libs/1_56_0/doc/html/boost/lockfree/queue.html #include <include/tbb/tbb.h>
#include <pthread.h>
#include <iostream>
using namespace std; #define NUM_THREAD 10
class person {
public:
person() {
}
person(int name, unsigned int thread_num){
this->name = name;
this->thread_num = thread_num;
} void print() {
printf("%u\t%u\n", thread_num, name);
}
private:
int name;
unsigned int thread_num;
}; tbb::strict_ppl::concurrent_queue<person*> que; void* consumer(void* arg) {
cout << arg << endl;
while(true) {
if(que.empty()) {
cout << '.' << flush;
sleep();
}
person* p;
if(que.try_pop(p)) {
p->print();
}
}
} void* producer(void* arg) {
cout << arg << endl;
unsigned int thread_num =(unsigned int)pthread_self();
for(int i=; i<; i++) {
person* p = new person(i, thread_num);
que.push(p);
}
} int main()
{
pthread_t tids_c[NUM_THREAD];
for(int i=; i<NUM_THREAD; i++) {
int ret = pthread_create(&tids_c[i], NULL, consumer, NULL);
if(ret != ) {
cout << "start consumer failed" << endl;
return -;
}
} pthread_t tids[NUM_THREAD];
for(int i=; i<NUM_THREAD; i++) {
int ret = pthread_create(&tids[i], NULL, producer, NULL);
if(ret != ) {
cout << "start produer failed" << endl;
return -;
}
} for(int i=; i<NUM_THREAD; i++){
pthread_join(tids[i], NULL);
pthread_join(tids_c[i], NULL);
} cout << "exit" << endl;
} /* vim: set ts=4 sw=4 sts=4 tw=100 */
dic = {}
with open('log.txt') as f:
while True:
line = f.readline()
if not line:
break;
line = line.strip() arr = line.split('\t')
key = arr[] if key not in dic:
dic[key] =
else:
dic[key] += for key in dic:
print key, dic[key]
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAADkAAAC2CAIAAADsnLLfAAADdklEQVR4nO2d3ZGDMAyEqYuCPJNuKCFV0AzFcA+QwwaRSCLymszu22UY+E7xjxbJd93z+Xw8Hl2pfpjmVWPqvqw0zrnEB/TDNE9Dv/tUZG1UZI0RWWN0wrqsBPpFQL5+m/LHSe2QwJrGeZ6GYdSynly/fNx33fqbXF/9DqxpXO6alK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