main.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // Created by zx on 2020/6/18.
  3. //
  4. #include <iostream>
  5. #include <glog/logging.h>
  6. #include "TaskQueue/TQFactory.h"
  7. #include "./communication/communication_socket_base.h"
  8. #include "StoreProcessTask.h"
  9. #include "system_communicator.h"
  10. #include "Locate_communicator.h"
  11. #include "threadSafeQueue.h"
  12. ///线程池
  13. tq::IQueue* g_pthread_queue = nullptr;
  14. Error_manager Init_communicators();
  15. int main(int argc,char* argv[])
  16. {
  17. Error_manager code=Init_communicators();
  18. if(code!=SUCCESS)
  19. {
  20. LOG(ERROR)<<code.to_string();
  21. }
  22. g_pthread_queue= tq::TQFactory::CreateDefaultQueue();
  23. g_pthread_queue->Start(6);
  24. //std::thread* pthread=new std::thread(delete_thread);
  25. int N=0;
  26. while(1)
  27. {
  28. usleep(10);
  29. StoreProcessTask* task=new StoreProcessTask();
  30. task->init_task(rand(),rand()%6);
  31. if(g_pthread_queue->TaskCount()<12)
  32. {
  33. g_pthread_queue->AddTask(task);
  34. N++;
  35. printf("task size / pushed size : %d / %d\n",g_pthread_queue->TaskCount(),N);
  36. }
  37. else
  38. {
  39. delete task;
  40. }
  41. }
  42. g_pthread_queue->WaitForFinish();
  43. delete g_pthread_queue;
  44. return 0;
  45. }
  46. Error_manager Init_communicators()
  47. {
  48. Error_manager code;
  49. if(Locate_communicator::get_instance_pointer()== nullptr)
  50. return FAILED;
  51. code=Locate_communicator::get_instance_pointer()->communication_connect("tcp://127.0.0.1:9006");
  52. if(code!=SUCCESS)
  53. {
  54. return code;
  55. }
  56. Locate_communicator::get_instance_pointer()->communication_run();
  57. ///最后初始化与终端通讯的对象
  58. if(System_communicator::get_instance_pointer()== nullptr)
  59. return FAILED;
  60. return SUCCESS;
  61. }