summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/thread_test.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/test/thread_test.cpp b/test/thread_test.cpp
index fd7a411..63ec347 100644
--- a/test/thread_test.cpp
+++ b/test/thread_test.cpp
@@ -1,19 +1,43 @@
#include <iostream>
#include "raul/Thread.hpp"
+#include "raul/Semaphore.hpp"
using namespace std;
using namespace Raul;
+class Waiter : public Raul::Thread {
+public:
+ Waiter(Semaphore& sem) : _sem(sem) {
+ Thread::set_name("Waiter");
+ }
+
+private:
+ void _run() {
+ cout << "[Waiter] Waiting for signal..." << endl;
+ _sem.wait();
+ cout << "[Waiter] Received signal, exiting" << endl;
+ }
+
+ Semaphore& _sem;
+};
+
int
main()
{
Thread& this_thread = Thread::get();
this_thread.set_name("Main");
- cout << "Thread name should be Main" << endl;
+ Semaphore sem(0);
+ Waiter waiter(sem);
+ waiter.start();
+
+ cout << "[Main] Signaling..." << endl;
+ sem.post();
- cout << "Thread name: " << Thread::get().name() << endl;
+ cout << "[Main] Waiting for waiter..." << endl;
+ waiter.join();
+
+ cout << "[Main] Exiting" << endl;
return 0;
}
-