// File: suyash[P]chan/chan_test.cc
// Function: unbuffered_chan_multi_with_pause_Test::TestBody()
TEST(unbuffered_chan, multi_with_pause) {
	chan::unbuffered_chan<int> c;

	std::thread pool[100];

	std::atomic<int> blocked_count;
	blocked_count.store(0);

	auto sender = [&blocked_count](chan::write_chan<int>& c){
		blocked_count++;
		c << 1;
	};

	for (int i = 0 ; i < 50 ; i++) {
		pool[i] = std::thread(sender, std::ref(c));
	}

	// wait for 50 threads to get blocked
	while (true) {
		if (blocked_count.load() == 50) {
			break;
		}
	}

	auto receiver = [](chan::read_chan<int>& c){
		int _ = 0;
		c >> _;
	};

	for (int i = 50 ; i < 100 ; i++) {
		pool[i] = std::thread(receiver, std::ref(c));
	}

	for (int i = 0 ; i < 100 ; i++) {
		pool[i].join();
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x530, %rsp            # imm = 0x530
movq %rdi, -0x38(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x4c150
leaq -0x460(%rbp), %rax
movq %rax, %rcx
addq $0x320, %rcx            # imm = 0x320
movq %rcx, -0x4c8(%rbp)
movq %rax, -0x4c0(%rbp)
movq -0x4c0(%rbp), %rdi
movq %rdi, -0x4d0(%rbp)
callq 0x4c730
movq -0x4d0(%rbp), %rax
movq -0x4c8(%rbp), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
movq %rax, -0x4c0(%rbp)
jne 0x4813a
leaq -0x464(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x5, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x4e0(%rbp)
movl -0x28(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x4f8c0
movl %eax, -0x4d4(%rbp)
jmp 0x481a4
movl -0x4d4(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x4e4(%rbp)
movl -0x24(%rbp), %ecx
movl %ecx, -0x30(%rbp)
subl $0x3, %eax
je 0x481de
jmp 0x481c3
movl -0x4e4(%rbp), %eax
subl $0x5, %eax
je 0x481ec
jmp 0x481d0
movq -0x4e0(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x48202
movq -0x4e0(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x48202
movq -0x4e0(%rbp), %rcx
movl -0x30(%rbp), %eax
xchgl %eax, (%rcx)
jmp 0x48202
movq %rax, %rdi
callq 0x29080
leaq -0x464(%rbp), %rax
movq %rax, -0x470(%rbp)
movl $0x0, -0x474(%rbp)
cmpl $0x32, -0x474(%rbp)
jge 0x482c6
leaq -0x138(%rbp), %rdi
callq 0x4c800
movq %rax, -0x488(%rbp)
leaq -0x480(%rbp), %rdi
leaq -0x470(%rbp), %rsi
leaq -0x488(%rbp), %rdx
callq 0x484b0
jmp 0x48256
movslq -0x474(%rbp), %rax
leaq -0x460(%rbp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x480(%rbp), %rsi
callq 0x4c780
leaq -0x480(%rbp), %rdi
callq 0x4c1f0
movl -0x474(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x474(%rbp)
jmp 0x4821a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x490(%rbp)
movl %eax, -0x494(%rbp)
leaq -0x460(%rbp), %rax
movq %rax, -0x4f8(%rbp)
addq $0x320, %rax            # imm = 0x320
movq %rax, -0x4f0(%rbp)
jmp 0x48465
jmp 0x482c8
jmp 0x482ca
leaq -0x464(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x5, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x508(%rbp)
movl -0xc(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x4f8c0
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x4fc(%rbp)
decl %eax
subl $0x2, %eax
jb 0x48324
jmp 0x48309
movl -0x4fc(%rbp), %eax
subl $0x5, %eax
je 0x48332
jmp 0x48316
movq -0x508(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x4833e
movq -0x508(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x4833e
movq -0x508(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
cmpl $0x32, -0x14(%rbp)
jne 0x48346
jmp 0x48348
jmp 0x482c8
movl $0x32, -0x49c(%rbp)
cmpl $0x64, -0x49c(%rbp)
jge 0x483c8
leaq -0x138(%rbp), %rdi
callq 0x4c800
movq %rax, -0x4b0(%rbp)
leaq -0x4a8(%rbp), %rdi
leaq -0x495(%rbp), %rsi
leaq -0x4b0(%rbp), %rdx
callq 0x48570
jmp 0x4838a
movslq -0x49c(%rbp), %rax
leaq -0x460(%rbp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x4a8(%rbp), %rsi
callq 0x4c780
leaq -0x4a8(%rbp), %rdi
callq 0x4c1f0
movl -0x49c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x49c(%rbp)
jmp 0x48352
movl $0x0, -0x4b4(%rbp)
cmpl $0x64, -0x4b4(%rbp)
jge 0x48404
movslq -0x4b4(%rbp), %rax
leaq -0x460(%rbp,%rax,8), %rdi
callq 0xab70
jmp 0x483f1
jmp 0x483f3
movl -0x4b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4b4(%rbp)
jmp 0x483d2
leaq -0x460(%rbp), %rax
movq %rax, -0x518(%rbp)
addq $0x320, %rax            # imm = 0x320
movq %rax, -0x510(%rbp)
movq -0x510(%rbp), %rdi
addq $-0x8, %rdi
movq %rdi, -0x520(%rbp)
callq 0x4c1f0
movq -0x518(%rbp), %rcx
movq -0x520(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x510(%rbp)
jne 0x4841f
leaq -0x138(%rbp), %rdi
callq 0x4c220
addq $0x530, %rsp            # imm = 0x530
popq %rbp
retq
movq -0x4f0(%rbp), %rdi
addq $-0x8, %rdi
movq %rdi, -0x528(%rbp)
callq 0x4c1f0
movq -0x4f8(%rbp), %rcx
movq -0x528(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x4f0(%rbp)
jne 0x48465
leaq -0x138(%rbp), %rdi
callq 0x4c220
movq -0x490(%rbp), %rdi
callq 0xabc0
nop