How to avoid deadlocking on finite channel

Because you lock the channel manually, and try to then put! elements inside? put! will internally lock the channel, you shouldn’t manually lock it, and it will wait to be able to lock.

Also, if your second thread manually locks c and then you try to take! and there are no elements it will hang forever as nothing can put anything into c as it is locked.