// File: HQarroum[P]thread-pool/examples/working-with-functors/main.cpp
// Function: main
int main() {
  // Producer and consumer thread pools.
  thread::pool::pool_t pool_of_consumers(5);

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

  // Creating the callable.
  auto callable = thread::pool::bind(pool_of_consumers, static_void_function);

  // Scheduling the producers.
  for (size_t i = 0; i < work_to_spawn; ++i) {
    auto result = callable(i);
    assert(result.get() == (int) (i + 1));
  }
  
  // Waiting for the consumers to complete.
  while (count < work_to_spawn)
    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;

  return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x360, %rsp            # imm = 0x360
movl $0x0, -0x4(%rbp)
leaq -0x2a0(%rbp), %rdi
movq %rdi, -0x328(%rbp)
movl $0x5, %esi
callq 0x3be0
callq 0x3040
movq -0x328(%rbp), %rsi
movq %rax, -0x2a8(%rbp)
leaq -0x74(%rip), %rdx       # 0x3520
leaq -0x2d0(%rbp), %rdi
callq 0x3800
jmp 0x35a2
movq $0x0, -0x2e8(%rbp)
cmpq $0x3e8, -0x2e8(%rbp) # imm = 0x3E8
jae 0x3698
movq -0x2e8(%rbp), %rdx
leaq -0x2f8(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x3cf0
jmp 0x35da
leaq -0x2f8(%rbp), %rdi
callq 0x3d30
movl %eax, -0x32c(%rbp)
jmp 0x35ee
movl -0x32c(%rbp), %eax
movq -0x2e8(%rbp), %rcx
addq $0x1, %rcx
cmpl %ecx, %eax
jne 0x3605
jmp 0x3675
leaq 0x14d9c(%rip), %rdi     # 0x183a8
leaq 0x14db3(%rip), %rsi     # 0x183c6
movl $0x2a, %edx
leaq 0x14db0(%rip), %rcx     # 0x183cf
callq 0x3180
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2d8(%rbp)
movl %eax, -0x2dc(%rbp)
jmp 0x37df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2d8(%rbp)
movl %eax, -0x2dc(%rbp)
jmp 0x37d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2d8(%rbp)
movl %eax, -0x2dc(%rbp)
leaq -0x2f8(%rbp), %rdi
callq 0x3da0
jmp 0x37d3
leaq -0x2f8(%rbp), %rdi
callq 0x3da0
movq -0x2e8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2e8(%rbp)
jmp 0x35ad
jmp 0x369a
leaq 0x20b87(%rip), %rdi     # 0x24228
callq 0x3dc0
cmpq $0x3e8, %rax            # imm = 0x3E8
jae 0x36dd
movl $0x64, -0x304(%rbp)
leaq -0x300(%rbp), %rdi
leaq -0x304(%rbp), %rsi
callq 0x3ef0
jmp 0x36cd
leaq -0x300(%rbp), %rdi
callq 0x3e40
jmp 0x36db
jmp 0x369a
callq 0x3040
movq %rax, -0x310(%rbp)
leaq -0x310(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x3f10
movq %rax, -0x338(%rbp)
jmp 0x3705
movq -0x338(%rbp), %rax
movq %rax, -0x320(%rbp)
leaq -0x318(%rbp), %rdi
leaq -0x320(%rbp), %rsi
callq 0x3f60
jmp 0x3728
movq 0x20889(%rip), %rdi     # 0x23fb8
leaq 0x14ca4(%rip), %rsi     # 0x183da
callq 0x3250
movq %rax, -0x340(%rbp)
jmp 0x3744
leaq -0x318(%rbp), %rdi
callq 0x3fa0
movsd %xmm0, -0x348(%rbp)
jmp 0x375a
movsd -0x348(%rbp), %xmm0
movq -0x340(%rbp), %rdi
callq 0x33b0
movq %rax, -0x350(%rbp)
jmp 0x3777
movq -0x350(%rbp), %rdi
leaq 0x14c65(%rip), %rsi     # 0x183ea
callq 0x3250
movq %rax, -0x358(%rbp)
jmp 0x3793
movq -0x358(%rbp), %rdi
movq 0x207bf(%rip), %rsi     # 0x23f60
callq 0x3290
jmp 0x37a8
movl $0x0, -0x4(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0x3fc0
leaq -0x2a0(%rbp), %rdi
callq 0x3fe0
movl -0x4(%rbp), %eax
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
leaq -0x2d0(%rbp), %rdi
callq 0x3fc0
leaq -0x2a0(%rbp), %rdi
callq 0x3fe0
movq -0x2d8(%rbp), %rdi
callq 0x3390
nopw (%rax,%rax)