00001
00002
00003
00004
00005
00006
00007 #include <iostream>
00008 #include <stdlib.h>
00009 #include <unistd.h>
00010 #include <string.h>
00011
00012 #include "ComPlusPlus/ComPlusPlus"
00013
00014 int main( int argc, char * argv [] ) {
00015
00016 if ( argc != 2 ) {
00017 std::cout << "usage: ExampleSem post|wait|local\n";
00018 exit (1);
00019 }
00020
00021 if ( strcmp ( argv [ 1 ], "post") == 0 ) {
00022 compp::Sem *s1 = new compp::Sem ( true, 1 ) ;
00023 for ( int i = 0; i++ < 10; ) {
00024 s1->Post();
00025 }
00026
00027 } else {
00028 if ( strcmp ( argv [ 1 ], "wait") == 0 ) {
00029 compp::Sem *s1 = new compp::Sem ( true, 1 ) ;
00030
00031 for ( int i = 0; i++ < 10; ) {
00032 s1->Wait();
00033 }
00034 } else {
00035
00036 compp::Sem *s1 = new compp::Sem ( ) ;
00037 std::cout << "***************** Semaphore *****************\n";
00038 for ( int i = 0; i++ < 10; ) {
00039
00040 s1->Post();
00041 }
00042
00043 for ( int l = 0; l++ < 10; ) {
00044
00045 s1->Wait();
00046 }
00047 std::cout << "***************** OK *****************\n";
00048 }
00049 }
00050 return 0;
00051 }