Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

tlock.cc

Go to the documentation of this file.
00001 /* Copyright (C) 2003 Herbert Straub
00002  *
00003  * This program is free software; you can redistribute it and/or modify
00004  * it under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation; either version 2 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 }

Generated on Fri Aug 20 10:58:08 2004 for NewsCache by doxygen 1.3.6-20040222