fork download
  1. /*This code is in RTOS environment*/
  2. /*Title: The wretched alternative.*/
  3. /*This is wrong version*/
  4.  
  5. /*This code invites semaphore bugs or shared-data bugs everywhere*/
  6.  
  7. // File: tmrtask.c
  8.  
  9. long int lSecondsToday; //global variable
  10.  
  11. void vTimerTask(void){
  12. .
  13. .
  14. .
  15. GetSemaphore(SEMAPHORE_TIME_OF_DAY); //this function is provided by RTOS vendor
  16. ++lSecondsToday;
  17. if(lSecondsToday == 60 * 60 * 24){
  18. lSecondsToday = 0L;
  19. }
  20. GiveSemaphore(SEMAPHORE_TIME_OF_DAY);
  21. .
  22. .
  23. .
  24. }
  25. -----------------------------------------------------
  26. // File: hacker.c
  27.  
  28. extern long int lSecondsToday;
  29.  
  30. void vHackerTask(void){
  31. .
  32. .
  33. .
  34. /*Hope he remembers to use the semaphore*/
  35. lDeadline = lSecondsToday + 1800L
  36. .
  37. .
  38. .
  39. /*Here, too*/
  40. if(lSecondsToday > 3600 * 12)
  41. .
  42. .
  43. .
  44. }
  45. -----------------------------------------------------
  46. // File: junior.c
  47.  
  48. extern long int lSecondsToday;
  49.  
  50. void vJuniorProgrammerTask (void){
  51. .
  52. .
  53. .
  54. /*Hope junior remembers to use the semaphore here. too*/
  55. for(l = lSecondsToday; l < lSecondsToday + 10; ++l)
  56. .
  57. .
  58. .
  59. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘vTimerTask’:
prog.c:12:2: error: expected expression before ‘.’ token
  .
  ^
prog.c:20:2: warning: implicit declaration of function ‘GiveSemaphore’ [-Wimplicit-function-declaration]
  GiveSemaphore(SEMAPHORE_TIME_OF_DAY);
  ^~~~~~~~~~~~~
prog.c:20:16: error: ‘SEMAPHORE_TIME_OF_DAY’ undeclared (first use in this function)
  GiveSemaphore(SEMAPHORE_TIME_OF_DAY);
                ^~~~~~~~~~~~~~~~~~~~~
prog.c:20:16: note: each undeclared identifier is reported only once for each function it appears in
prog.c:21:2: error: expected expression before ‘.’ token
  .
  ^
prog.c: At top level:
prog.c:25:1: error: expected identifier or ‘(’ before ‘--’ token
 -----------------------------------------------------
 ^~
prog.c: In function ‘vHackerTask’:
prog.c:31:2: error: expected expression before ‘.’ token
  .
  ^
prog.c: At top level:
prog.c:45:1: error: expected identifier or ‘(’ before ‘--’ token
 -----------------------------------------------------
 ^~
prog.c: In function ‘vJuniorProgrammerTask’:
prog.c:51:2: error: expected expression before ‘.’ token
  .
  ^
stdout
Standard output is empty