// File: /workspace/github_cpp_makefile_star2_O2/waket[P]ThreadPool/main.cpp
// Function: main
int main(int argc, char* argv[])
{
   int result = 0;
   cout << "The purpose of this code is to show the usage of ThreadPoolTask library." << endl << endl;
   srand ( time(NULL) );

   // Synchronous start and stop
   {
      ThreadPoolTask tpt;
      cout << "Adding Taks... " << endl;
      for (unsigned int i = 0; i < random() % 15; i++)
          tpt.doTask(hello);
      cout << "Adding task... DONE" << endl;

      cout << "Starting ThreadPoolTask... " << endl;
      if (tpt.start())
      {
         cout << "Starting ThreadPoolTask DONE" << endl;
      }
      else
      {
         cout << "Starting ThreadPoolTask ERROR" << endl;
      }

      cout << "Adding task... " << endl;
      for (unsigned int i = 0; i < random() % 15; i++)
          tpt.doTask(hello);
      cout << "Adding task... DONE" << endl;

      sleep(random() % 15);

      cout << "Stopping ThreadPoolTask... " << endl;
      if (tpt.stop())
      {
         cout << "Stopping ThreadPoolTask DONE" << endl;
      }
      else
      {
         cout << "Stopping ThreadPoolTask ERROR" << endl;
      }
   }
   // Synchronous start and asynchronous stop
   {
      ThreadPoolTask tpt;
      cout << "Adding task... " << endl;
      for (unsigned int i = 0; i < random() % 15; i++)
          tpt.doTask(hello);
      cout << "Adding task... DONE" << endl;

      cout << "Starting ThreadPoolTask... " << endl;
      if (tpt.start())
      {
         cout << "Starting ThreadPoolTask DONE" << endl;
      }
      else
      {
         cout << "Starting ThreadPoolTask ERROR" << endl;
      }

      cout << "Adding task... " << endl;
      for (unsigned int i = 0; i < random() % 5; i++)
          tpt.doTask(hello);
      cout << "Adding task... DONE" << endl;

      cout << "Set worker count to ... " << endl;
      if (tpt.setWorkerCount(3)) {
          cout << "Set worker count DONE" << endl;
      }
      else
      {
          cout << "Set worker count ERROR" << endl;
      }

      sleep(random() % 10);

      cout << "Requesting ThreadPoolTask stop... " << endl;
      if (tpt.requestStop())
      {
         cout << "Requesting ThreadPoolTask stop DONE" << endl;
      }
      else
      {
         cout << "Requesting ThreadPoolTask stop ERROR" << endl;
      }

//      cout << "Requesting ThreadPoolTask stop... " << endl;
//      if (tpt.requestStop())
//      {
//         cout << "Requesting ThreadPoolTask stop DONE" << endl;
//      }
//      else
//      {
//         cout << "Requesting ThreadPoolTask stop ERROR" << endl;
//      }
//
//      cout << "Adding task... " << endl;
//      for (unsigned int i = 0; i < random() % 15; i++)
//          tpt.doTask(hello);
//      cout << "Adding task... DONE" << endl;

      cout << "Blocking for stop... " << endl;
      if (tpt.wait())
      {
         cout << "Blocking for stop DONE" << endl;
      }
      else
      {
         cout << "Blocking for stop ERROR" << endl;
      }
   }
   // Done
   cout << "OK" << endl;
   return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq 0x5abd(%rip), %rbx      # 0x7fd8
leaq 0x2b05(%rip), %rsi      # 0x5027
movq %rbx, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
movq %rax, %rdi
callq 0x20a0
xorl %edi, %edi
callq 0x2180
movl %eax, %edi
callq 0x2190
leaq 0x20(%rsp), %rdi
callq 0x29c6
leaq 0x2b17(%rip), %rsi      # 0x5070
movq %rbx, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
xorl %r12d, %r12d
pushq $0xf
popq %r13
leaq -0xfb(%rip), %rbx       # 0x247c
movq %rsp, %r14
leaq 0x20(%rsp), %r15
callq 0x20c0
cqto
idivq %r13
cmpq %r12, %rdx
jle 0x25b6
andq $0x0, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2ce4
movq %r15, %rdi
movq %r14, %rsi
callq 0x357e
movq %r14, %rdi
callq 0x2a7a
incq %r12
jmp 0x257f
movq 0x5a1b(%rip), %rdi      # 0x7fd8
leaq 0x2abc(%rip), %rsi      # 0x5080
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
movq 0x5a00(%rip), %rdi      # 0x7fd8
leaq 0x2ab5(%rip), %rsi      # 0x5094
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
leaq 0x20(%rsp), %rdi
callq 0x3318
leaq 0x2ab3(%rip), %rcx      # 0x50b0
leaq 0x2ac9(%rip), %rbx      # 0x50cd
testb %al, %al
movq %rbx, %rsi
cmovneq %rcx, %rsi
movq 0x59c4(%rip), %rdi      # 0x7fd8
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
movq 0x59b0(%rip), %rdi      # 0x7fd8
leaq 0x2abc(%rip), %rsi      # 0x50eb
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
xorl %ebp, %ebp
leaq -0x1c9(%rip), %r14      # 0x247c
movq %rsp, %r15
leaq 0x20(%rsp), %r12
callq 0x20c0
cqto
idivq %r13
cmpq %rbp, %rdx
jle 0x2684
andq $0x0, (%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x2ce4
movq %r12, %rdi
movq %r15, %rsi
callq 0x357e
movq %r15, %rdi
callq 0x2a7a
incq %rbp
jmp 0x264d
movq 0x594d(%rip), %rdi      # 0x7fd8
leaq 0x29ee(%rip), %rsi      # 0x5080
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
callq 0x20c0
cqto
idivq %r13
movq %rdx, %rdi
callq 0x2120
movq 0x5920(%rip), %rdi      # 0x7fd8
leaq 0x2a3c(%rip), %rsi      # 0x50fb
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
leaq 0x20(%rsp), %rdi
callq 0x33e4
leaq 0x2a3a(%rip), %rcx      # 0x5117
leaq 0x2a50(%rip), %rsi      # 0x5134
testb %al, %al
cmovneq %rcx, %rsi
movq 0x58e7(%rip), %rdi      # 0x7fd8
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
leaq 0x20(%rsp), %rdi
callq 0x2e1c
leaq 0x20(%rsp), %rdi
callq 0x29c6
movq 0x58bf(%rip), %rdi      # 0x7fd8
leaq 0x29cb(%rip), %rsi      # 0x50eb
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
xorl %ebp, %ebp
leaq -0x2ba(%rip), %r14      # 0x247c
movq %rsp, %r15
leaq 0x20(%rsp), %r12
callq 0x20c0
cqto
idivq %r13
cmpq %rbp, %rdx
jle 0x2775
andq $0x0, (%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x2ce4
movq %r12, %rdi
movq %r15, %rsi
callq 0x357e
movq %r15, %rdi
callq 0x2a7a
incq %rbp
jmp 0x273e
movq 0x585c(%rip), %rdi      # 0x7fd8
leaq 0x28fd(%rip), %rsi      # 0x5080
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
movq 0x5841(%rip), %rdi      # 0x7fd8
leaq 0x28f6(%rip), %rsi      # 0x5094
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
leaq 0x20(%rsp), %rdi
callq 0x3318
testb %al, %al
leaq 0x28f2(%rip), %rax      # 0x50b0
cmovneq %rax, %rbx
movq 0x580f(%rip), %rdi      # 0x7fd8
movq %rbx, %rsi
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
movq 0x57f8(%rip), %rdi      # 0x7fd8
leaq 0x2904(%rip), %rsi      # 0x50eb
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
xorl %r12d, %r12d
pushq $0x5
popq %r13
leaq -0x386(%rip), %rbx      # 0x247c
movq %rsp, %r14
leaq 0x20(%rsp), %r15
callq 0x20c0
cqto
idivq %r13
cmpq %r12, %rdx
jle 0x2841
andq $0x0, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2ce4
movq %r15, %rdi
movq %r14, %rsi
callq 0x357e
movq %r14, %rdi
callq 0x2a7a
incq %r12
jmp 0x280a
movq 0x5790(%rip), %rdi      # 0x7fd8
leaq 0x2831(%rip), %rsi      # 0x5080
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
movq 0x5775(%rip), %rdi      # 0x7fd8
leaq 0x28e8(%rip), %rsi      # 0x5152
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
leaq 0x20(%rsp), %rdi
pushq $0x3
popq %rsi
callq 0x375c
leaq 0x28e0(%rip), %rcx      # 0x516b
leaq 0x28ef(%rip), %rsi      # 0x5181
testb %al, %al
cmovneq %rcx, %rsi
movq 0x5739(%rip), %rdi      # 0x7fd8
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
callq 0x20c0
pushq $0xa
popq %rcx
cqto
idivq %rcx
movq %rdx, %rdi
callq 0x2120
movq 0x5710(%rip), %rdi      # 0x7fd8
leaq 0x28c9(%rip), %rsi      # 0x5198
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
leaq 0x20(%rsp), %rdi
callq 0x36c0
leaq 0x28ce(%rip), %rcx      # 0x51bb
leaq 0x28eb(%rip), %rsi      # 0x51df
testb %al, %al
cmovneq %rcx, %rsi
movq 0x56d7(%rip), %rdi      # 0x7fd8
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
movq 0x56c3(%rip), %rdi      # 0x7fd8
leaq 0x28e8(%rip), %rsi      # 0x5204
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
leaq 0x20(%rsp), %rdi
callq 0x3648
leaq 0x28e0(%rip), %rcx      # 0x521a
leaq 0x28f0(%rip), %rsi      # 0x5231
testb %al, %al
cmovneq %rcx, %rsi
movq 0x568a(%rip), %rdi      # 0x7fd8
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
leaq 0x20(%rsp), %rdi
callq 0x2e1c
movq 0x566c(%rip), %rdi      # 0x7fd8
leaq 0x28d6(%rip), %rsi      # 0x5249
callq 0x21a0
movq %rax, %rdi
callq 0x20a0
xorl %eax, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x29b1
jmp 0x29b1
jmp 0x29a4
jmp 0x29b1
jmp 0x29a4
jmp 0x29b1
jmp 0x29a4
jmp 0x29b1
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2a7a
jmp 0x29b4
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2e1c
movq %rbx, %rdi
callq 0x22e0