Advertisement
Guest User

Untitled

a guest
May 29th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. // ConsoleApplication31.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include <string>
  5. using namespace std;
  6.  
  7. class Semafor{
  8. private:
  9. static Semafor* uniq;
  10. int count;
  11. Semafor(){
  12. count=0;
  13. }
  14. ~Semafor(){
  15. }
  16. public:
  17. static Semafor* getInstance(){
  18. if(uniq==NULL)
  19. uniq=new Semafor();
  20. uniq->count++;
  21. if(uniq->count>4)
  22. throw "Eroare";
  23. return uniq;
  24. }
  25. };
  26. Semafor* Semafor::uniq=NULL;
  27.  
  28. int main()
  29. {
  30. try{
  31. Semafor::getInstance();
  32. Semafor::getInstance();
  33. Semafor::getInstance();
  34. Semafor::getInstance();
  35. Semafor::getInstance();
  36. Semafor::getInstance();
  37. }
  38. catch(string *s)
  39. {
  40. printf("%s\n",s->c_str());
  41. }
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement