#include <include/tbb/tbb.h>#include<pthread.h>#include<iostream>using namespacestd;#defineNum_thread 10classPerson { Public: Person () {} person (intName, unsignedintthread_num) { This->name =name; This->thread_num =Thread_num; } voidprint () {printf ("%u\t%u\n", Thread_num, name); }Private: intname; unsignedintThread_num;}; Tbb::strict_ppl::concurrent_queue<person*>que;void* Consumer (void*Arg) {cout<< Arg <<Endl; while(true) { if(Que.empty ()) {cout<<'.'<<Flush; Sleep (1); } Person*p; if(Que.try_pop (P)) {p-print (); } }}void* Producer (void*Arg) {cout<< Arg <<Endl; unsignedintThread_num = (unsignedint) pthread_self (); for(intI=0; i<Ten; i++) { person* p =NewPerson (I, thread_num); Que.push (P); }}intMain () {pthread_t tids_c[num_thread]; for(intI=0; i<num_thread; i++) { intret = Pthread_create (&Tids_c[i], NULL, consumer, NULL); if(Ret! =0) {cout<<"Start consumer failed"<<Endl; return-1; }} pthread_t Tids[num_thread]; for(intI=0; i<num_thread; i++) { intret = Pthread_create (&Tids[i], NULL, producer, NULL); if(Ret! =0) {cout<<"Start Produer failed"<<Endl; return-1; } } for(intI=0; 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') asF: whileTrue:line=F.readline ()ifNot line : Break; Line=Line.strip () arr= Line.split ('\ t') Key= arr[1] ifKey notinchDic:dic[key]=1 Else: Dic[key]+=1 forKeyinchdic:print Key, Dic[key]
c+= concurrent_queue thread Safety test