jack2 codebase
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.

93 lines
2.1KB

  1. /*
  2. Copyright (C) 2004-2005 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #include <stdio.h>
  16. #include <sys/time.h>
  17. #include <stdlib.h>
  18. #include <pthread.h>
  19. #include <sys/time.h>
  20. #include <errno.h>
  21. #include <unistd.h>
  22. #include <fcntl.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include <exception>
  26. pthread_t fThread;
  27. char fName[256];
  28. int fFifo;
  29. void* ThreadHandler(void* arg)
  30. {
  31. char c;
  32. printf("ThreadHandler\n");
  33. try {
  34. while (1) {
  35. read(fFifo, &c, sizeof(c));
  36. sleep(1);
  37. //pthread_testcancel();
  38. }
  39. } catch (std::exception e) {}
  40. }
  41. int main(int argc, char * const argv[])
  42. {
  43. int res;
  44. void* status;
  45. struct stat statbuf;
  46. printf("Thread test\n");
  47. std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
  48. sprintf(fName, "/tmp/fifo");
  49. if (stat(fName, &statbuf)) {
  50. if (errno == ENOENT) {
  51. if (mkfifo(fName, 0666) < 0) {
  52. printf("Cannot create inter-client FIFO [%s]\n", fName);
  53. return 0;
  54. }
  55. } else {
  56. printf("Cannot check on FIFO %s\n", fName);
  57. return 0;
  58. }
  59. } else {
  60. if (!S_ISFIFO(statbuf.st_mode)) {
  61. printf("FIFO (%s) already exists, but is not a FIFO!\n", fName);
  62. return 0;
  63. }
  64. }
  65. if ((fFifo = open(fName, O_RDWR|O_CREAT, 0666)) < 0) {
  66. printf("Cannot open fifo [%s]", fName);
  67. return 0;
  68. }
  69. if (res = pthread_create(&fThread, 0, ThreadHandler, NULL)) {
  70. printf("Cannot set create thread %d\n", res);
  71. return 0;
  72. }
  73. sleep(3);
  74. printf("Cancel Thread\n");
  75. pthread_cancel(fThread);
  76. pthread_join(fThread, &status);
  77. }