When I was a young man in Army training many years ag, I actually fell asleep while walking a guard post one night. I was in the middle of Advanceed Individual Training (AIT) for infantry at Ft.ix. ONe of the things you were traiined on was walking guard duty. The problem was that when you got selected for a night of guard duty, you did not get excused from the normal day's training, which was very exhausting on its own. Instead, while your mates were getting their 6 1/2 hours sleep back in the barracks, those of us on guard duty were walking a guard post 1 hour on, 2 hours off, all night long. And you couldn't get 2 hours sleep in you r time off, that 2 hours started when the guard truck picked you up at your post, and ended when it dropped you off for your next tour of duty. So more than 1/2 hour of yout 2-hour 'break' was spent being transported in a bouncing 2 1/2 ton truck, where sleep was almost impossible. Short story: you became increasingly exhausted as the night went on. So I was walking my solitary post and dozed off, waking up as I was falling over, caught my self before hard impact with the ground, then went scrambling after my rifle, which I had of course dropped. So you can fall asleep in almost any situation if you're tired enough. A colleaugue of mine, years later, told me of going through Ranger training, where you went on a 48-hour exercize with no sleep time; a group was wading through a swampy area in chelt-deep wated with their rifles over their heads, and another soldier fell asleep and fell face first into the swamp, dropping his rifle.
That said, if you were ever that tired, masturbating or having sex would likely be pretty far from your mind (though I was young & had I seen a comely lass beckoning to me in the middle of the night, I doubt I'd have turned her down in favor of a nap!).
But for me the answer would be never & never.