12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- //
- // Created by zx on 2020/6/18.
- //
- #include <iostream>
- #include <glog/logging.h>
- #include "TaskQueue/TQFactory.h"
- #include "./communication/communication_socket_base.h"
- #include "StoreProcessTask.h"
- #include "system_communicator.h"
- #include "Locate_communicator.h"
- #include "threadSafeQueue.h"
- ///线程池
- tq::IQueue* g_pthread_queue = nullptr;
- Error_manager Init_communicators();
- int main(int argc,char* argv[])
- {
- Error_manager code=Init_communicators();
- if(code!=SUCCESS)
- {
- LOG(ERROR)<<code.to_string();
- }
- g_pthread_queue= tq::TQFactory::CreateDefaultQueue();
- g_pthread_queue->Start(6);
- //std::thread* pthread=new std::thread(delete_thread);
- int N=0;
- while(1)
- {
- usleep(10);
- StoreProcessTask* task=new StoreProcessTask();
- task->init_task(rand(),rand()%6);
- if(g_pthread_queue->TaskCount()<12)
- {
- g_pthread_queue->AddTask(task);
- N++;
- printf("task size / pushed size : %d / %d\n",g_pthread_queue->TaskCount(),N);
- }
- else
- {
- delete task;
- }
- }
- g_pthread_queue->WaitForFinish();
- delete g_pthread_queue;
- return 0;
- }
- Error_manager Init_communicators()
- {
- Error_manager code;
- if(Locate_communicator::get_instance_pointer()== nullptr)
- return FAILED;
- code=Locate_communicator::get_instance_pointer()->communication_connect("tcp://127.0.0.1:9006");
- if(code!=SUCCESS)
- {
- return code;
- }
- Locate_communicator::get_instance_pointer()->communication_run();
- ///最后初始化与终端通讯的对象
- if(System_communicator::get_instance_pointer()== nullptr)
- return FAILED;
- return SUCCESS;
- }
|