A new template for Lab 5 (Consumer Producer Assignment) based on the old one.
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.

40 lines
627 B

  1. #include "thread.h"
  2. void create_thread(thread_t *t, void (*f)(queue *), queue *q)
  3. {
  4. #ifdef UNIX
  5. pthread_create((pthread_t *) t, NULL, (void *(*)(void *)) f, q);
  6. #endif
  7. #ifdef WINDOWS
  8. *t = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) f, q, 0, NULL);
  9. #endif
  10. }
  11. void wait_for_threads(thread_t *ts, int c)
  12. {
  13. #ifdef UNIX
  14. if (c == 1)
  15. {
  16. pthread_join(*ts, NULL);
  17. }
  18. else
  19. {
  20. for (int i = 0; i < c; ++i)
  21. {
  22. pthread_join(ts[i], NULL);
  23. }
  24. }
  25. #endif
  26. #ifdef WINDOWS
  27. if (c == 1)
  28. {
  29. WaitForSingleObject(*ts, INFINITE);
  30. }
  31. else
  32. {
  33. WaitForMultipleObjects(c, ts, true, INFINITE);
  34. }
  35. #endif
  36. }