// File: /workspace/github_cpp_makefile_star2_O1/HQarroum[P]thread-pool/examples/many-producers-many-consumers/main.cpp
// Function: main
int main() {
  // Producer and consumer thread pools.
  thread::pool::pool_t pool_of_consumers(5);
  thread::pool::pool_t pool_of_producers(5);

  // Counting the start time.
  auto start = std::chrono::high_resolution_clock::now();

  // Array of producer workers.
  auto producers = new std::function<void()>[workers_to_spawn];
  // Filling the array with the producers.
  std::fill_n(producers, workers_to_spawn, std::bind(producer, &pool_of_consumers));

  // Scheduling the producers.
  pool_of_producers.schedule_bulk(producers, workers_to_spawn);

  // Waiting for the producers to complete.
  pool_of_producers.stop().await();
  
  // Waiting for the consumers to complete.
  while (count < workers_to_spawn * work_by_worker)
    std::this_thread::sleep_for(std::chrono::milliseconds(100));

  // Measuring and dumping the elapsed time.
  auto end = std::chrono::high_resolution_clock::now();
  std::chrono::duration<double, std::milli> diff = end - start;
  std::cout << "Elasped time : " << diff.count() << " ms" << std::endl;

  // Deleting the producer array.
  delete[] producers;
  return (0);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x540, %rsp            # imm = 0x540
leaq 0x2a8(%rsp), %r15
movl $0x5, %esi
movq %r15, %rdi
callq 0x3a6e
leaq 0x10(%rsp), %rdi
movl $0x5, %esi
callq 0x3a6e
callq 0x3060
movq %rax, %r14
movl $0x7d08, %edi           # imm = 0x7D08
callq 0x3030
movq %rax, %rbx
movq $0x3e8, (%rax)          # imm = 0x3E8
leaq 0x8(%rax), %r12
movl $0x7d00, %edx           # imm = 0x7D00
movq %r12, %rdi
xorl %esi, %esi
callq 0x3120
leaq -0xb8(%rip), %rax       # 0x361d
movq %rsp, %r13
movq %rax, (%r13)
movq %r15, 0x8(%r13)
movl $0x8, %r15d
leaq (%rbx,%r15), %rdi
movq %r13, %rsi
callq 0x6b72
addq $0x20, %r15
cmpq $0x7d08, %r15           # imm = 0x7D08
jne 0x36e6
leaq 0x10(%rsp), %r13
movl $0x3e8, %edx            # imm = 0x3E8
movq %r13, %rdi
movq %r12, %rsi
callq 0x3b36
movb $0x1, %al
xchgb %al, 0x290(%r13)
movq (%r13), %r15
movq 0x8(%r13), %r12
cmpq %r12, %r15
je 0x3738
movq %r15, %rdi
callq 0x3360
addq $0x8, %r15
jmp 0x3725
movq 0x9ae1(%rip), %rax      # 0xd220
cmpq $0xf423f, %rax          # imm = 0xF423F
ja 0x3784
movq %rsp, %r15
movq $0x0, (%rsp)
movq $0x5f5e100, 0x8(%rsp)   # imm = 0x5F5E100
movq %r15, %rdi
movq %r15, %rsi
callq 0x30b0
cmpl $-0x1, %eax
jne 0x3775
callq 0x3050
cmpl $0x4, (%rax)
je 0x375b
movq 0x9aa4(%rip), %rax      # 0xd220
cmpq $0xf4240, %rax          # imm = 0xF4240
jb 0x374a
callq 0x3060
movq %rax, %r15
movq 0x9825(%rip), %rdi      # 0xcfb8
leaq 0x4896(%rip), %rsi      # 0x8030
movl $0xf, %edx
callq 0x3290
subq %r14, %r15
cvtsi2sd %r15, %xmm0
divsd 0x4854(%rip), %xmm0     # 0x8008
movq 0x97fd(%rip), %rdi      # 0xcfb8
callq 0x3310
movq %rax, %r14
leaq 0x4876(%rip), %rsi      # 0x8040
movl $0x3, %edx
movq %rax, %rdi
callq 0x3290
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
movq (%rbx), %rax
movq %rax, %r14
shlq $0x5, %r14
testq %rax, %rax
je 0x383b
movq %r14, %r12
negq %r12
leaq (%r14,%rbx), %r15
addq $-0x18, %r15
movq 0x10(%r15), %rax
testq %rax, %rax
je 0x3831
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
addq $-0x20, %r15
addq $0x20, %r12
jne 0x381b
orq $0x8, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x33b0
leaq 0x10(%rsp), %rdi
callq 0x3b92
leaq 0x2a8(%rsp), %rdi
callq 0x3b92
xorl %eax, %eax
addq $0x540, %rsp            # imm = 0x540
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x3889
movq %rax, %rbx
jmp 0x3896
jmp 0x3889
movq %rax, %rdi
callq 0x3c7b
jmp 0x3889
jmp 0x3889
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3b92
leaq 0x2a8(%rsp), %rdi
callq 0x3b92
movq %rbx, %rdi
callq 0x3380
nop