-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated some programs, added async.cpp
- Loading branch information
Showing
6 changed files
with
79 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* Async fizzbuzz | ||
* Tanner Babcock | ||
* November 19, 2023 */ | ||
#define _GLIBCXX_USE_NANOSLEEP | ||
#include <iostream> | ||
#include <string> | ||
#include <thread> | ||
|
||
void callback(const std::string& data) { | ||
std::cout << "Callback called with: " << data << std::endl; | ||
} | ||
|
||
void task(int time) { | ||
std::this_thread::sleep_for(std::chrono::seconds(time)); | ||
callback("async task done"); | ||
} | ||
|
||
int main(void) { | ||
std::thread *bt = new std::thread(task, 1); | ||
std::cout << "async task started" << std::endl; | ||
std::this_thread::sleep_for(std::chrono::seconds(3)); | ||
for (int x = 0; x < 100; x++) { | ||
if (x % 5 == 0) | ||
std::cout << "buzz"; | ||
if (x % 3 == 0) | ||
std::cout << "fizz"; | ||
else if (x % 5 != 0) | ||
std::cout << x; | ||
std::cout << std::endl; | ||
} | ||
std::cout << "main done" << std::endl; | ||
bt->join(); | ||
delete bt; | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters