00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <iostream>
00018
00019 #include <stdio.h>
00020 #include <unistd.h>
00021
00022 #include "Logger.h"
00023 #include "ObjLock.h"
00024
00025 Logger slog;
00026
00027 using namespace std;
00028
00029 int main(int argc, char **argv)
00030 {
00031 fork();
00032 try {
00033 class ObjLock ObjLock(string("lock_test.file"));
00034
00035 cout << "Trying get shared lock" << endl;
00036 ObjLock.lockShBlk();
00037 cout << "Shared gelockt." << endl;
00038
00039 sleep(10);
00040
00041 cout << "Trying unlock..." << endl;
00042 ObjLock.unlock();
00043 cout << "unlocked" << endl;
00044
00045 cout << "Trying get exclusive lock" << endl;
00046 if (ObjLock.lockExNoBlk() == ObjLock::not_locked) {
00047 cout << "get NO lock" << endl;
00048 } else {
00049 cout << "get lock" << endl;
00050 ObjLock.unlock();
00051 }
00052
00053 cout << "Trying get exclusive lock" << endl;
00054 ObjLock.lockExBlk();
00055 cout << "exlusive gelockt." << endl;
00056
00057 sleep(10);
00058
00059 cout << "Trying unlock..." << endl;
00060 ObjLock.unlock();
00061 cout << "unlocked" << endl;
00062 }
00063 catch(...) {
00064 cout << "Error Handler" << endl;
00065 perror("ErrorText");
00066 exit(1);
00067 }
00068
00069 }