Advertisement
LupusOssorum

Separate Thread Input

Nov 1st, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. import std.stdio;
  2. import queue : Queue;
  3. import core.thread : Thread;
  4.  
  5. class ThreadInput : Thread {
  6. private Queue!string queue;
  7.  
  8. this(Queue!string queue) {
  9. super(&run);
  10. this.queue = queue;
  11. }
  12.  
  13. private void run() {
  14. while (true) {
  15. queue.put(readln);
  16. }
  17. }
  18. }
  19.  
  20. void main() {
  21. Queue!string inputQueue = new Queue!string;
  22. ThreadInput threadInput = new ThreadInput(inputQueue);
  23. threadInput.start;
  24.  
  25. while (true) {
  26. foreach (string value; inputQueue) {
  27. writeln(value);
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement