Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.8KB

  1. /*
  2. * Carla Tests
  3. * Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the GPL.txt file
  16. */
  17. #include "CarlaThread.hpp"
  18. class MyThread : public CarlaThread
  19. {
  20. public:
  21. MyThread(bool wait)
  22. : blockWait(wait)
  23. {
  24. }
  25. protected:
  26. void run()
  27. {
  28. printf("RUN(%i)\n", blockWait);
  29. if (blockWait)
  30. {
  31. for (int i=0; i < 100; i++)
  32. {
  33. carla_msleep(50);
  34. printf("RUN(%i) - BLOCKING\n", blockWait);
  35. }
  36. }
  37. printf("RUN(%i) - FINISHED\n", blockWait);
  38. }
  39. private:
  40. bool blockWait;
  41. };
  42. int main()
  43. {
  44. MyThread t1(false);
  45. MyThread t2(true);
  46. MyThread t3(true);
  47. MyThread t4(true);
  48. MyThread t5(false);
  49. t1.start();
  50. t2.start();
  51. //t3.start();
  52. //t3.waitForStarted();
  53. //t3.stop();
  54. t1.waitForStarted();
  55. t2.waitForStarted();
  56. printf("THREADS STARTED\n");
  57. // test if threds keep working
  58. carla_sleep(1);
  59. printf("THREAD1 STOPPING...\n");
  60. if (t1.isRunning() && ! t1.stop(500))
  61. {
  62. printf("THREAD1 FAILED, TERMINATE\n");
  63. t1.terminate();
  64. }
  65. printf("THREAD2 STOPPING...\n");
  66. if (t2.isRunning() && ! t2.stop(500))
  67. {
  68. printf("THREAD2 FAILED, TERMINATE\n");
  69. t2.terminate();
  70. }
  71. return 0;
  72. }