// File: /workspace/github_cpp_makefile_star2_O2/guoxuanhan[P]NetServer/threadpool.cpp
// Function: ThreadPool::ThreadFunc()
void ThreadPool::ThreadFunc()
{
    std::thread::id tid = std::this_thread::get_id();
    std::stringstream sin;
    sin << tid;
    std::cout<< "Worker thread is running! tid: " << tid << std::endl;
    Task task;
    while(started_)
    {
        task = NULL;
        {
            std::unique_lock<std::mutex> lock(mutex_);//unique_lock支持解锁又上锁的情况
            while(taskqueue_.empty() && started_)
            {
                condition_.wait(lock);
            }
            if(!started_)
            {
                break;
            }
            std::cout<< "Thread wake up! tid: " << tid << std::endl;
            std::cout<< "Taskqueue size: " << taskqueue_.size() << std::endl;
            task = taskqueue_.front();
            taskqueue_.pop();
        }
        if(task)
        {
            try
            {
                task();//task()中IO过程可以使用协程优化，让出CPU资源
            } catch(std::bad_alloc& bad)
            {
                std::cerr << "Bad_alloc caught in ThreadPool::ThreadFunc task: " << bad.what() << std::endl;
                while(true);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, %rbx
callq 0x42d0
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x4250
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x5b5f
movq 0xb294(%rip), %rdi      # 0x17fb8
leaq 0x28ec(%rip), %rsi      # 0xf617
callq 0x4300
movq %rax, %rdi
movq %r14, %rsi
callq 0x5b5f
movq %rax, %rdi
callq 0x41a0
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r15
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
leaq 0x70(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x98(%rbx), %r13
leaq 0x20(%rbx), %rax
movq %rax, (%rsp)
leaq 0x10(%rsp), %r12
cmpb $0x1, (%rbx)
jne 0xce52
movq %r15, %rdi
xorl %esi, %esi
callq 0xd012
movq %r12, %rdi
movq 0x8(%rsp), %rsi
callq 0xd042
movq 0x50(%rbx), %rcx
movb (%rbx), %al
cmpq 0x30(%rbx), %rcx
jne 0xcdb2
testb $0x1, %al
je 0xce48
movq %r13, %rdi
movq %r12, %rsi
callq 0x40d0
jmp 0xcd91
testb $0x1, %al
je 0xce48
movq 0xb1f7(%rip), %rdi      # 0x17fb8
leaq 0x286f(%rip), %rsi      # 0xf637
callq 0x4300
movq %rax, %rdi
movq %r14, %rsi
callq 0x5b5f
movq %rax, %rdi
callq 0x41a0
movq 0xb1d1(%rip), %rdi      # 0x17fb8
leaq 0x285f(%rip), %rsi      # 0xf64d
callq 0x4300
movq %rax, %rbp
movq (%rsp), %rdi
callq 0xd5a4
movq %rbp, %rdi
movq %rax, %rsi
callq 0x4230
movq %rax, %rdi
callq 0x41a0
movq 0x30(%rbx), %rsi
movq %r15, %rdi
callq 0x4a8c
movq (%rsp), %rdi
callq 0xd780
movq %r12, %rdi
callq 0xd058
cmpq $0x0, 0x30(%rsp)
je 0xcd71
movq %r15, %rdi
callq 0x4a7c
jmp 0xcd71
leaq 0x10(%rsp), %rdi
callq 0xd058
leaq 0x20(%rsp), %rdi
callq 0x4a60
leaq 0x40(%rsp), %rdi
callq 0x4270
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
cmpl $0x1, %edx
jne 0xcee8
movq %rbx, %rdi
callq 0x4140
movq %rax, %rbx
movq 0xb156(%rip), %rdi      # 0x17fe8
leaq 0x27c5(%rip), %rsi      # 0xf65e
callq 0x4300
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x4300
movq %rax, %rdi
callq 0x41a0
jmp 0xcebd
movq %rax, %rbx
callq 0x4510
jmp 0xcee8
movq %rax, %rdi
callq 0x4ada
movq %rax, %rbx
jmp 0xcee8
movq %rax, %rbx
jmp 0xcef2
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xd058
leaq 0x20(%rsp), %rdi
callq 0x4a60
leaq 0x40(%rsp), %rdi
callq 0x4270
movq %rbx, %rdi
callq 0x4570