mutex: use cerr for printing debug info

This commit is contained in:
PowerUser64 2024-11-25 22:42:17 -08:00
parent 160d22ded8
commit 22a12e2995

View file

@ -6,7 +6,7 @@
#include <cstddef> // size_t
#include <cstring> // memset
#include <ctime>
#include <iostream> // cout
#include <iostream> // cerr
#include <vector> // vector
// used for threads
@ -50,7 +50,7 @@ void *thread_task_increment(const struct thread_data &thread) {
SLEEP;
std::cout << "Hello from thread " << thread.id << "! (before run loop)"
std::cerr << "Hello from thread " << thread.id << "! (before run loop)"
<< std::endl;
SLEEP;
@ -61,7 +61,7 @@ void *thread_task_increment(const struct thread_data &thread) {
// non-mutex operations
{
std::cout << "Hello from thread " << thread.id
std::cerr << "Hello from thread " << thread.id
<< "! (inside run loop, before mutex)" << std::endl;
}
@ -83,7 +83,7 @@ void *thread_task_increment(const struct thread_data &thread) {
// enter the mutex
std::cout << "Hello from thread " << thread.id
std::cerr << "Hello from thread " << thread.id
<< "! (inside run loop, inside mutex)" << std::endl;
SLEEP;
@ -105,7 +105,7 @@ void *thread_task_increment(const struct thread_data &thread) {
}
}
std::cout << "Hello from thread " << thread.id << "! (done)" << std::endl;
std::cerr << "Hello from thread " << thread.id << "! (done)" << std::endl;
pthread_exit(nullptr);
}
@ -155,7 +155,7 @@ void do_threading(struct thread_group threads) {
SLEEP;
}
std::cout << "Threads have been spawned." << std::endl;
std::cerr << "Threads have been spawned." << std::endl;
// loop until all threads are done
for (size_t finished_threads = 0; finished_threads < threads.total_threads;) {