// File: HQarroum[P]thread-pool/examples/one-producer-many-consumers/main.cpp
// Function: main
int main() {

  // A list of futures.
  std::list<std::future<void>> list;

  // Producer and consumer thread pools.
  thread::pool::parameterized_pool_t<1, 0> pool_of_consumers(std::thread::hardware_concurrency() + 1);

  // Scheduling the producers.
  for (size_t i = 0; i < work_to_spawn; ++i) {
    list.push_back(pool_of_consumers.schedule(static_void_function));
  }
  
  // Counting the start time.
  auto start = std::chrono::high_resolution_clock::now();

  // Waiting for the consumers to complete.
  for (std::future<void>& future : list) {
    future.wait();
  }

  // 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;

  return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x350, %rsp            # imm = 0x350
movl $0x0, -0x4(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x3a80
callq 0x32e0
incl %eax
movl %eax, %esi
leaq -0x2b8(%rbp), %rdi
callq 0x3aa0
jmp 0x3552
movq $0x0, -0x2d0(%rbp)
cmpq $0x2710, -0x2d0(%rbp) # imm = 0x2710
jae 0x360d
leaq 0x23b(%rip), %rdx       # 0x37b0
leaq -0x2e0(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x3bf0
jmp 0x358a
leaq -0x20(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x3bb0
jmp 0x359c
leaq -0x2e0(%rbp), %rdi
callq 0x3de0
movq -0x2d0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2d0(%rbp)
jmp 0x355d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c0(%rbp)
movl %eax, -0x2c4(%rbp)
jmp 0x3793
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c0(%rbp)
movl %eax, -0x2c4(%rbp)
jmp 0x3787
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c0(%rbp)
movl %eax, -0x2c4(%rbp)
leaq -0x2e0(%rbp), %rdi
callq 0x3de0
jmp 0x3787
callq 0x3040
movq %rax, -0x2e8(%rbp)
leaq -0x20(%rbp), %rax
movq %rax, -0x2f0(%rbp)
movq -0x2f0(%rbp), %rdi
callq 0x3e00
movq %rax, -0x2f8(%rbp)
movq -0x2f0(%rbp), %rdi
callq 0x3e30
movq %rax, -0x300(%rbp)
leaq -0x2f8(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x3e60
testb $0x1, %al
jne 0x3663
jmp 0x3694
leaq -0x2f8(%rbp), %rdi
callq 0x3e90
movq %rax, -0x308(%rbp)
movq -0x308(%rbp), %rdi
callq 0x3eb0
jmp 0x3684
jmp 0x3686
leaq -0x2f8(%rbp), %rdi
callq 0x3ee0
jmp 0x364a
callq 0x3040
movq %rax, -0x310(%rbp)
leaq -0x310(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0x3f00
movq %rax, -0x328(%rbp)
jmp 0x36bc
movq -0x328(%rbp), %rax
movq %rax, -0x320(%rbp)
leaq -0x318(%rbp), %rdi
leaq -0x320(%rbp), %rsi
callq 0x3f50
jmp 0x36df
movq 0x208d2(%rip), %rdi     # 0x23fb8
leaq 0x14c9b(%rip), %rsi     # 0x18388
callq 0x3250
movq %rax, -0x330(%rbp)
jmp 0x36fb
leaq -0x318(%rbp), %rdi
callq 0x3f90
movsd %xmm0, -0x338(%rbp)
jmp 0x3711
movsd -0x338(%rbp), %xmm0
movq -0x330(%rbp), %rdi
callq 0x33b0
movq %rax, -0x340(%rbp)
jmp 0x372e
movq -0x340(%rbp), %rdi
leaq 0x14c5c(%rip), %rsi     # 0x18398
callq 0x3250
movq %rax, -0x348(%rbp)
jmp 0x374a
movq -0x348(%rbp), %rdi
movq 0x20808(%rip), %rsi     # 0x23f60
callq 0x3280
jmp 0x375f
movl $0x0, -0x4(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x3fb0
leaq -0x20(%rbp), %rdi
callq 0x4030
movl -0x4(%rbp), %eax
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
leaq -0x2b8(%rbp), %rdi
callq 0x3fb0
leaq -0x20(%rbp), %rdi
callq 0x4030
movq -0x2c0(%rbp), %rdi
callq 0x3390
nopl (%rax,%rax)