mutex: use cerr for printing debug info
This commit is contained in:
parent
160d22ded8
commit
22a12e2995
1 changed files with 6 additions and 6 deletions
12
main.cpp
12
main.cpp
|
@ -6,7 +6,7 @@
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
#include <cstring> // memset
|
#include <cstring> // memset
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream> // cout
|
#include <iostream> // cerr
|
||||||
#include <vector> // vector
|
#include <vector> // vector
|
||||||
|
|
||||||
// used for threads
|
// used for threads
|
||||||
|
@ -50,7 +50,7 @@ void *thread_task_increment(const struct thread_data &thread) {
|
||||||
|
|
||||||
SLEEP;
|
SLEEP;
|
||||||
|
|
||||||
std::cout << "Hello from thread " << thread.id << "! (before run loop)"
|
std::cerr << "Hello from thread " << thread.id << "! (before run loop)"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
SLEEP;
|
SLEEP;
|
||||||
|
@ -61,7 +61,7 @@ void *thread_task_increment(const struct thread_data &thread) {
|
||||||
|
|
||||||
// non-mutex operations
|
// non-mutex operations
|
||||||
{
|
{
|
||||||
std::cout << "Hello from thread " << thread.id
|
std::cerr << "Hello from thread " << thread.id
|
||||||
<< "! (inside run loop, before mutex)" << std::endl;
|
<< "! (inside run loop, before mutex)" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ void *thread_task_increment(const struct thread_data &thread) {
|
||||||
|
|
||||||
// enter the mutex
|
// enter the mutex
|
||||||
|
|
||||||
std::cout << "Hello from thread " << thread.id
|
std::cerr << "Hello from thread " << thread.id
|
||||||
<< "! (inside run loop, inside mutex)" << std::endl;
|
<< "! (inside run loop, inside mutex)" << std::endl;
|
||||||
|
|
||||||
SLEEP;
|
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);
|
pthread_exit(nullptr);
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ void do_threading(struct thread_group threads) {
|
||||||
SLEEP;
|
SLEEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Threads have been spawned." << std::endl;
|
std::cerr << "Threads have been spawned." << std::endl;
|
||||||
|
|
||||||
// loop until all threads are done
|
// loop until all threads are done
|
||||||
for (size_t finished_threads = 0; finished_threads < threads.total_threads;) {
|
for (size_t finished_threads = 0; finished_threads < threads.total_threads;) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue