Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: base/cpp101/sleep.cc

Issue 23506012: Example solution for C++ 101 Exercise 3 (message loops) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to 224002 Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/base.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdio.h>
6
7 #include "base/at_exit.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/time/time.h"
13
14 int main(int argc, char* argv[]) {
15 base::AtExitManager exit_manager;
16
17 if (argc <= 1) {
18 printf("%s: missing operand\n", argv[0]);
19 return -1;
20 }
21
22 int duration_seconds = 0;
23 if (!base::StringToInt(argv[1], &duration_seconds) ||
24 duration_seconds < 0) {
25 printf("%s: invalid time interval `%s'\n", argv[0], argv[1]);
26 return -1;
27 }
28
29 base::TimeDelta duration = base::TimeDelta::FromSeconds(duration_seconds);
30
31 base::MessageLoop main_loop;
32
33 base::RunLoop run_loop;
34
35 main_loop.PostDelayedTask(FROM_HERE, run_loop.QuitClosure(), duration);
36
37 run_loop.Run();
38
39 return 0;
40 }
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698