#include <why.h>
#include <why-thread.h>
#include <why-messagequeue.h>
#include <why-irq.h>
#include <why-time.h>

int main()
{
    Why::init();

    Why::MessageQueue<int> q1(7);
    Why::MessageQueue<int> q2(5);

    Why::IRQ::connect(7,  [&q1](int){auto ok = q1.put_noblock(1); assert(ok);});
    Why::IRQ::connect(42, [&q2](int){auto ok = q2.put_noblock(2); assert(ok);});

    Why::Thread t1([&q1](){                            // <-- stack memory usage
        while (true) {
            int elem = q1.get();                       // <-- blocks
            std::println("t1: {}", elem);
        }
    });
    Why::Thread t2([&q2](){                            // <-- stack memory usage
        while (true) {
            int elem = q2.get();                       // <-- blocks
            std::println("t2: {}", elem);
        }
    });

    return 0;
}
