+ 3

What delay or sleep function can be used for c++ in code playground?

I've tried: sleep(), usleep(), nanosleep(), std::this_thread::sleep_for(std::chrono::milliseconds()). neither of them work, so which sleep/delay function is available for c++ in code playground?

11th Jul 2017, 9:44 PM
Anthony Mans
Anthony Mans - avatar
6 Answers
+ 12
The Playground does "support" delaying functions, as in they will run, but all it does is make your output take longer (and make it more likely for the server to cut the session short on you). You won't see the pause in output, because the result is sent back in one chunk of plain text.
11th Jul 2017, 11:26 PM
Tamra
Tamra - avatar
+ 4
@Ace Isn't using sleep(); bad practice?
11th Jul 2017, 10:07 PM
Manual
Manual - avatar
+ 3
@Manual using sleep() is frowned upon. i dont use it, instead i use this_thread::sleep_for(chrono::<unit>(value) ). that doesn't work, so i'm looking for a way to delay output within code playground.
11th Jul 2017, 10:11 PM
Anthony Mans
Anthony Mans - avatar
+ 2
edit They are used for slowing down your code or for timing sections of code.
11th Jul 2017, 9:55 PM
Manual
Manual - avatar
+ 1
@Manual Sleep() allows your CPU to rest for a brief period, which significantly decreases CPU usage when you are executing something like an infinite loop. But if you are using it for timing stuff specifically, then yes it is a bad practice.
12th Jul 2017, 12:08 AM
aklex
aklex - avatar
+ 1
@aklex timer is what i want to do/create, or are there timer functions in c++ that work on playground? if not how would i go about making a timer if there is no suitable sleep/delay function?
12th Jul 2017, 12:17 AM
Anthony Mans
Anthony Mans - avatar