diff options
Diffstat (limited to 'netsvcs/clients/Tokens/deadlock')
-rw-r--r-- | netsvcs/clients/Tokens/deadlock/Makefile | 156 | ||||
-rw-r--r-- | netsvcs/clients/Tokens/deadlock/Makefile.am | 24 | ||||
-rw-r--r-- | netsvcs/clients/Tokens/deadlock/Makefile.bor | 5 | ||||
-rw-r--r-- | netsvcs/clients/Tokens/deadlock/README | 98 | ||||
-rw-r--r-- | netsvcs/clients/Tokens/deadlock/deadlock.dsp | 112 | ||||
-rw-r--r-- | netsvcs/clients/Tokens/deadlock/deadlock.dsw | 29 | ||||
-rw-r--r-- | netsvcs/clients/Tokens/deadlock/deadlock_detection_test.cpp | 341 |
7 files changed, 0 insertions, 765 deletions
diff --git a/netsvcs/clients/Tokens/deadlock/Makefile b/netsvcs/clients/Tokens/deadlock/Makefile deleted file mode 100644 index 29fb07d179a..00000000000 --- a/netsvcs/clients/Tokens/deadlock/Makefile +++ /dev/null @@ -1,156 +0,0 @@ -#---------------------------------------------------------------------------- -# $Id$ -# -# Makefile for repeating token client application -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# Local macros -#---------------------------------------------------------------------------- - -FILES = deadlock_detection_test - -LSRC = $(addsuffix .cpp,$(FILES)) -LOBJ = $(LSRC:%.cpp=$(VDIR)%.o) -SHOBJ = $(addsuffix .so,$(FILES)) - -BIN2 = deadlock_detection_test - -#### If the ACE library wasn't built with sufficient components, don't -#### try to build here. -ACE_BUILD_COMPONENTS := $(shell sh $(ACE_ROOT)/bin/ace_components --ace) -ifeq (Token,$(findstring Token,$(ACE_BUILD_COMPONENTS))) - BIN = $(BIN2) -endif # Token - -#---------------------------------------------------------------------------- -# Include macros and targets -#---------------------------------------------------------------------------- - -include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU -include $(ACE_ROOT)/include/makeinclude/macros.GNU -include $(ACE_ROOT)/include/makeinclude/rules.common.GNU -include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU -include $(ACE_ROOT)/include/makeinclude/rules.lib.GNU -include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU -include $(ACE_ROOT)/include/makeinclude/rules.local.GNU - -#---------------------------------------------------------------------------- -# Local targets -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# Dependencies -#---------------------------------------------------------------------------- - -# IF YOU PUT ANYTHING HERE IT WILL GO AWAY -# DO NOT DELETE THIS LINE -- g++dep uses it. -# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. - -.obj/deadlock_detection_test.o .obj/deadlock_detection_test.so .shobj/deadlock_detection_test.o .shobj/deadlock_detection_test.so: deadlock_detection_test.cpp \ - $(ACE_ROOT)/ace/OS.h \ - $(ACE_ROOT)/ace/inc_user_config.h \ - $(ACE_ROOT)/ace/streams.h \ - $(ACE_ROOT)/ace/Basic_Types.h \ - $(ACE_ROOT)/ace/Basic_Types.i \ - $(ACE_ROOT)/ace/Trace.h \ - $(ACE_ROOT)/ace/OS.i \ - $(ACE_ROOT)/ace/Log_Msg.h \ - $(ACE_ROOT)/ace/Log_Record.h \ - $(ACE_ROOT)/ace/ACE.h \ - $(ACE_ROOT)/ace/ACE.i \ - $(ACE_ROOT)/ace/Log_Priority.h \ - $(ACE_ROOT)/ace/Log_Record.i \ - $(ACE_ROOT)/ace/Token_Manager.h \ - $(ACE_ROOT)/ace/Synch.h \ - $(ACE_ROOT)/ace/SV_Semaphore_Complex.h \ - $(ACE_ROOT)/ace/SV_Semaphore_Simple.h \ - $(ACE_ROOT)/ace/SV_Semaphore_Simple.i \ - $(ACE_ROOT)/ace/SV_Semaphore_Complex.i \ - $(ACE_ROOT)/ace/Synch.i \ - $(ACE_ROOT)/ace/Synch_T.h \ - $(ACE_ROOT)/ace/Event_Handler.h \ - $(ACE_ROOT)/ace/Event_Handler.i \ - $(ACE_ROOT)/ace/Synch_T.i \ - $(ACE_ROOT)/ace/Thread.h \ - $(ACE_ROOT)/ace/Thread.i \ - $(ACE_ROOT)/ace/Atomic_Op.i \ - $(ACE_ROOT)/ace/Synch_T.cpp \ - $(ACE_ROOT)/ace/Map_Manager.h \ - $(ACE_ROOT)/ace/Map_Manager.i \ - $(ACE_ROOT)/ace/Map_Manager.cpp \ - $(ACE_ROOT)/ace/Malloc.h \ - $(ACE_ROOT)/ace/Malloc_Base.h \ - $(ACE_ROOT)/ace/Malloc.i \ - $(ACE_ROOT)/ace/Malloc_T.h \ - $(ACE_ROOT)/ace/Free_List.h \ - $(ACE_ROOT)/ace/Free_List.i \ - $(ACE_ROOT)/ace/Free_List.cpp \ - $(ACE_ROOT)/ace/Malloc_T.i \ - $(ACE_ROOT)/ace/Malloc_T.cpp \ - $(ACE_ROOT)/ace/Memory_Pool.h \ - $(ACE_ROOT)/ace/Signal.h \ - $(ACE_ROOT)/ace/Containers.h \ - $(ACE_ROOT)/ace/Containers.i \ - $(ACE_ROOT)/ace/Containers_T.h \ - $(ACE_ROOT)/ace/Containers_T.i \ - $(ACE_ROOT)/ace/Containers_T.cpp \ - $(ACE_ROOT)/ace/Signal.i \ - $(ACE_ROOT)/ace/Object_Manager.h \ - $(ACE_ROOT)/ace/Object_Manager.i \ - $(ACE_ROOT)/ace/Managed_Object.h \ - $(ACE_ROOT)/ace/Managed_Object.i \ - $(ACE_ROOT)/ace/Managed_Object.cpp \ - $(ACE_ROOT)/ace/Mem_Map.h \ - $(ACE_ROOT)/ace/Mem_Map.i \ - $(ACE_ROOT)/ace/Memory_Pool.i \ - $(ACE_ROOT)/ace/Service_Config.h \ - $(ACE_ROOT)/ace/Service_Object.h \ - $(ACE_ROOT)/ace/Shared_Object.h \ - $(ACE_ROOT)/ace/Shared_Object.i \ - $(ACE_ROOT)/ace/Service_Object.i \ - $(ACE_ROOT)/ace/SString.h \ - $(ACE_ROOT)/ace/SString.i \ - $(ACE_ROOT)/ace/Service_Config.i \ - $(ACE_ROOT)/ace/Reactor.h \ - $(ACE_ROOT)/ace/Handle_Set.h \ - $(ACE_ROOT)/ace/Handle_Set.i \ - $(ACE_ROOT)/ace/Timer_Queue.h \ - $(ACE_ROOT)/ace/Timer_Queue_T.h \ - $(ACE_ROOT)/ace/Timer_Queue_T.i \ - $(ACE_ROOT)/ace/Timer_Queue_T.cpp \ - $(ACE_ROOT)/ace/Reactor.i \ - $(ACE_ROOT)/ace/Reactor_Impl.h \ - $(ACE_ROOT)/ace/Svc_Conf_Tokens.h \ - $(ACE_ROOT)/ace/Local_Tokens.h \ - $(ACE_ROOT)/ace/Synch_Options.h \ - $(ACE_ROOT)/ace/Synch_Options.i \ - $(ACE_ROOT)/ace/Local_Tokens.i \ - $(ACE_ROOT)/ace/Token_Manager.i \ - $(ACE_ROOT)/ace/Remote_Tokens.h \ - $(ACE_ROOT)/ace/INET_Addr.h \ - $(ACE_ROOT)/ace/Addr.h \ - $(ACE_ROOT)/ace/Addr.i \ - $(ACE_ROOT)/ace/INET_Addr.i \ - $(ACE_ROOT)/ace/SOCK_Connector.h \ - $(ACE_ROOT)/ace/SOCK_Stream.h \ - $(ACE_ROOT)/ace/SOCK_IO.h \ - $(ACE_ROOT)/ace/SOCK.h \ - $(ACE_ROOT)/ace/IPC_SAP.h \ - $(ACE_ROOT)/ace/IPC_SAP.i \ - $(ACE_ROOT)/ace/SOCK.i \ - $(ACE_ROOT)/ace/SOCK_IO.i \ - $(ACE_ROOT)/ace/SOCK_Stream.i \ - $(ACE_ROOT)/ace/Time_Value.h \ - $(ACE_ROOT)/ace/SOCK_Connector.i \ - $(ACE_ROOT)/ace/Token_Request_Reply.h \ - $(ACE_ROOT)/ace/Token_Request_Reply.i \ - $(ACE_ROOT)/ace/Remote_Tokens.i \ - $(ACE_ROOT)/ace/Thread_Manager.h \ - $(ACE_ROOT)/ace/Thread_Manager.i \ - $(ACE_ROOT)/ace/Get_Opt.h \ - $(ACE_ROOT)/ace/Get_Opt.i \ - $(ACE_ROOT)/ace/Token_Invariants.h \ - $(ACE_ROOT)/ace/Token_Invariants.i - -# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/netsvcs/clients/Tokens/deadlock/Makefile.am b/netsvcs/clients/Tokens/deadlock/Makefile.am deleted file mode 100644 index 0b50b13195d..00000000000 --- a/netsvcs/clients/Tokens/deadlock/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -##---------------------------------------------------------------------------- -## $Id$ -## -## Makefile for repeating token client application -##---------------------------------------------------------------------------- - -## -## Process this file with automake to create Makefile.in -## - -## The number in AUTOMAKE_OPTIONS is the minimum required version automake -## needed to process this file. -AUTOMAKE_OPTIONS = 1.4 - -INCLUDES = -I$(top_builddir) -I$(top_srcdir) - -noinst_PROGRAMS = \ - deadlock_detection_test - -deadlock_detection_test_SOURCES = deadlock_detection_test.cpp -deadlock_detection_test_LDADD = \ - $(top_builddir)/netsvcs/lib/libnetsvcs.la \ - $(top_builddir)/ace/libACE.la - diff --git a/netsvcs/clients/Tokens/deadlock/Makefile.bor b/netsvcs/clients/Tokens/deadlock/Makefile.bor deleted file mode 100644 index 112a766ff2a..00000000000 --- a/netsvcs/clients/Tokens/deadlock/Makefile.bor +++ /dev/null @@ -1,5 +0,0 @@ - -NAME = deadlock_detection_test -OBJFILES=$(OBJDIR)\$(NAME).obj -!include <$(ACE_ROOT)\netsvcs\build.bor> - diff --git a/netsvcs/clients/Tokens/deadlock/README b/netsvcs/clients/Tokens/deadlock/README deleted file mode 100644 index 74fffde05cd..00000000000 --- a/netsvcs/clients/Tokens/deadlock/README +++ /dev/null @@ -1,98 +0,0 @@ - -deadlock_detection_test - -This example contains two deadlock tests, mutex and rwlock tests. -% ./deadlock_detection_test -u -./deadlock_detection_test: -[-r test readers/writer locks] -[-n <iterations>] -[-h <remote host>] -[-p <remote port>] -[-i ignore deadlock] - -For both mutex and rwlock tests, -h and -p specify to use remote -mutexes. -i specifies to ignore deadlock. -n is repetitions through -the respective algorithms (default 100). Both tests also use Token -Invariants to ensure correctness of the mutexes and readers/writer -locks. - ------------------------------------------------------------- - -If you run ./deadlock_detection_test without -r, then the following -mutex test is run. - -The mutex test spawns two threads which attempt to deadlock. -Logically, there are two tokens A and B. Here is what both threads -try to do: - -Thread 1 Thread 2 --------- -------- -Repeat 100 times Repeat 100 times - acquire A acquire B - acquire B acquire A - release A and B release A and B -repeat repeat - -Notice that A and B are reversed in 1 and 2. If the token manager -(which is not in the public interface, but hidden behind -ACE_Local_Mutex) works properly, they should detect the deadlock. If -a thread detects deadlock, the resources held are released, and it -starts the whole process over again. - -What can be confusing about the test program is all the other tricks -I'm pulling to test other aspects of the library. For instance, I'm -using both "global" and "local" ACE_Local_Mutexes. This is to test -the ability to have multiple threads using one token proxy as well as -multiple threads each using their own proxies. All the while, the -same logical token is being used. If this doesn't make sense, don't -worry about it. Just use the ACE_Local_Mutex any way you want. - -Another confusing trick is that I'm testing recursive acquisition. -(Two acquires in a row.) I have to make sure that the token manager -doesn't detect a recursive acquire as deadlock. - -To run a test, simply type: -% ./deadlock_detection_test - -This should run 100 times through the above pseudo code. If the -application halts, then we have trouble. It should never ever halt. -I've included a little flag with the ACE_Local_Mutex class to allow -deadlock detection to be ignored. So, if you run the test as follows, -deadlock detection will be ignored. - -% ./deadlock_detection_test -i - -In this case, the application should only run about a second before -deadlock occurs and the application halts. This is good. - ------------------------------------------------------------- - -If you run ./deadlock_detection_test *with* -r, then the following -rwlock test is run: - -There are four tokens and four threads in the rwlock test. The -readers/writer tokens are: - -reader first -writer first 1 -writer first 2 -writer first 3 - -There are three reader threads that only acquire reader locks on the -above tokens. Each of the reader threads first acquire "reader first" -and then one "writer first <tid>" (where <tid> is the corresponding -thread's id). So reader thread 1 acquires "reader first" and then -"writer first 1". - -There is a single writer thread that uses the following algorithm: - -repeat 100 - acquire "writer first 1" - acquire "reader first" - acquire "writer first 2" - acquire "reader first" - acquire "writer first 3" - acquire "reader first" - -This strange mix of readers and writer create an interesting graph of -tokens that the deadlock detection algorithm must traverse. diff --git a/netsvcs/clients/Tokens/deadlock/deadlock.dsp b/netsvcs/clients/Tokens/deadlock/deadlock.dsp deleted file mode 100644 index 29b18c0ffc9..00000000000 --- a/netsvcs/clients/Tokens/deadlock/deadlock.dsp +++ /dev/null @@ -1,112 +0,0 @@ -# Microsoft Developer Studio Project File - Name="NETSVCS Token Deadlock Client" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=NETSVCS Token Deadlock Client - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "deadlock.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "deadlock.mak"\
- CFG="NETSVCS Token Deadlock Client - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "NETSVCS Token Deadlock Client - Win32 Release" (based on\
- "Win32 (x86) Console Application")
-!MESSAGE "NETSVCS Token Deadlock Client - Win32 Debug" (based on\
- "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "NETSVCS Token Deadlock Client - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 ace.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\..\ace"
-# SUBTRACT LINK32 /incremental:yes
-
-!ELSEIF "$(CFG)" == "NETSVCS Token Deadlock Client - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir ""
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
-# SUBTRACT CPP /YX
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 aced.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\..\ace"
-
-!ENDIF
-
-# Begin Target
-
-# Name "NETSVCS Token Deadlock Client - Win32 Release"
-# Name "NETSVCS Token Deadlock Client - Win32 Debug"
-# Begin Group "Source"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=.\deadlock_detection_test.cpp
-
-!IF "$(CFG)" == "NETSVCS Token Deadlock Client - Win32 Release"
-
-# ADD CPP /MD
-# SUBTRACT CPP /YX
-
-!ELSEIF "$(CFG)" == "NETSVCS Token Deadlock Client - Win32 Debug"
-
-# ADD CPP /MDd
-# SUBTRACT CPP /YX
-
-!ENDIF
-
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/netsvcs/clients/Tokens/deadlock/deadlock.dsw b/netsvcs/clients/Tokens/deadlock/deadlock.dsw deleted file mode 100644 index 3ed309c0974..00000000000 --- a/netsvcs/clients/Tokens/deadlock/deadlock.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "deadlock"=.\deadlock.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/netsvcs/clients/Tokens/deadlock/deadlock_detection_test.cpp b/netsvcs/clients/Tokens/deadlock/deadlock_detection_test.cpp deleted file mode 100644 index 4a7b1bc5a39..00000000000 --- a/netsvcs/clients/Tokens/deadlock/deadlock_detection_test.cpp +++ /dev/null @@ -1,341 +0,0 @@ -// ============================================================================ -// $Id$ - -// -// = LIBRARY -// examples -// -// = FILENAME -// deadlock_detection_test.cpp -// -// = DESCRIPTION -// -// = AUTHOR -// Tim Harrison -// -// ============================================================================ - -#include "ace/OS.h" -#include "ace/Token_Manager.h" -#include "ace/Remote_Tokens.h" -#include "ace/Thread.h" -#include "ace/Thread_Manager.h" -#include "ace/Get_Opt.h" -#include "ace/Token_Invariants.h" - -ACE_RCSID(deadlock, deadlock_detection_test, "$Id$") - -#if defined (ACE_HAS_THREADS) - -typedef ACE_Token_Invariant_Manager ACE_TOKEN_INVARIANTS; - -static ACE_Token_Proxy *global_mutex; - -struct Two_Tokens -{ -public: - Two_Tokens (ACE_Thread_Manager *tm): thr_mgr_ (tm) {} - ACE_Token_Proxy *first_; - ACE_Token_Proxy *second_; - ACE_Thread_Manager *thr_mgr_; -}; - -struct Four_Tokens -{ -public: - Four_Tokens (ACE_Thread_Manager *tm): thr_mgr_ (tm) {} - ACE_Token_Proxy *first1_; - ACE_Token_Proxy *first2_; - ACE_Token_Proxy *first3_; - ACE_Token_Proxy *second_; - ACE_Thread_Manager *thr_mgr_; -}; - -static int ignore_deadlock = 0; -static int remote_mutexes = 0; -static const char *server_host = ACE_DEFAULT_SERVER_HOST; -static int server_port = ACE_DEFAULT_SERVER_PORT; -static int iterations = 100; -static int rwlocks = 0; - -static void * -two_token_thread (void *vp) -{ - Two_Tokens* tm = (Two_Tokens *) vp; - - for (int x = 0; x < iterations; x++) - { - if (tm->first_->acquire () == -1) - { - ACE_DEBUG ((LM_DEBUG, "Deadlock detected\n")); - continue; - } - - if (ACE_TOKEN_INVARIANTS::instance ()->acquired (tm->first_) == 0) - { - tm->first_->dump (); - ACE_ERROR_RETURN ((LM_ERROR, "violated invariant.\n"), 0); - } - - if (tm->second_->acquire () == -1) - { - ACE_DEBUG ((LM_DEBUG, "Deadlock Detected\n")); - goto G1; - } - - if (ACE_TOKEN_INVARIANTS::instance ()->acquired (tm->second_) == 0) - { - tm->second_->dump (); - ACE_ERROR_RETURN ((LM_ERROR, "violated invariant.\n"), 0); - } - - ACE_TOKEN_INVARIANTS::instance ()->releasing (tm->second_); - - tm->second_->release (); - G1: - ACE_TOKEN_INVARIANTS::instance ()->releasing (tm->first_); - - tm->first_->release (); - } - - ACE_DEBUG ((LM_DEBUG, "thread %t exiting\n")); - return 0; -} - -static void * -run_writer (void *vp) -{ - Four_Tokens *ft = (Four_Tokens *) vp; - int acquire_number = 0; - - for (int x = 0; x < iterations; x++) - { - // Cycle through each of the first three tokens. - ACE_Token_Proxy *t = 0; - switch (acquire_number) - { - case 0: - t = ft->first1_; - break; - case 1: - t = ft->first2_; - break; - case 2: - t = ft->first3_; - break; - } - - acquire_number = (acquire_number + 1) % 3; - - if (t->acquire () == -1) - { - ACE_ASSERT (errno == EDEADLK); - ACE_DEBUG ((LM_DEBUG, "Deadlock detected.\n")); - continue; - } - - if (ACE_TOKEN_INVARIANTS::instance ()->acquired (t) == 0) - { - t->dump (); - ACE_ERROR_RETURN ((LM_ERROR, "violated invariant.\n"), 0); - } - - if (ft->second_->acquire () == -1) - { - ACE_ASSERT (errno == EDEADLK); - ACE_DEBUG ((LM_DEBUG, "Deadlock Detected..\n")); - goto G1; - } - - if (ACE_TOKEN_INVARIANTS::instance ()->acquired (ft->second_) == 0) - { - ft->second_->dump (); - ACE_ERROR_RETURN ((LM_ERROR, "violated invariant.\n"), 0); - } - - ACE_TOKEN_INVARIANTS::instance ()->releasing (ft->second_); - - ft->second_->release (); - G1: - ACE_TOKEN_INVARIANTS::instance ()->releasing (t); - - t->release (); - } - - ACE_DEBUG ((LM_DEBUG, "thread %t exiting\n")); - return 0; -} - -static int -parse_args (int argc, char *argv[]) -{ - ACE_LOG_MSG->open (argv[0]); - - ACE_Get_Opt get_opt (argc, argv, "iuh:rp:n:", 1); - - for (int c; (c = get_opt ()) != -1; ) - { - switch (c) - { - case 'r': - rwlocks = 1; - break; - case 'i': - ignore_deadlock = 1; - break; - case 'h': - server_host = get_opt.optarg; - remote_mutexes = 1; - break; - case 'p': - server_port = ACE_OS::atoi (get_opt.optarg); - remote_mutexes = 1; - break; - case 'n': - iterations = ACE_OS::atoi (get_opt.optarg); - break; - case 'u': - default: - ACE_ERROR_RETURN ((LM_ERROR, - "%n:\n" - "[-r test readers/writer locks]\n" - "[-n <iterations>]\n" - "[-h <remote host>]\n" - "[-p <remote port>]\n" - "[-i ignore deadlock]\n%a", 1), -1); - } - } - - return 0; -} - -int -mutex_test (void) -{ - ACE_Thread_Manager thr_mgr; - - Two_Tokens one (&thr_mgr); - Two_Tokens two (&thr_mgr); - - if (remote_mutexes == 0) - { - global_mutex = new ACE_Local_Mutex ("global proxy", ignore_deadlock, 1); - one.first_ = new ACE_Local_Mutex ("local proxy", ignore_deadlock, 1); - two.second_ = new ACE_Local_Mutex ("local proxy", ignore_deadlock, 1); - } - else - { - ACE_Remote_Mutex::set_server_address (ACE_INET_Addr (server_port, server_host)); - global_mutex = new ACE_Remote_Mutex ("global proxy", ignore_deadlock, 1); - one.first_ = new ACE_Remote_Mutex ("local proxy", ignore_deadlock, 1); - two.second_ = new ACE_Remote_Mutex ("local proxy", ignore_deadlock, 1); - } - - one.second_ = global_mutex; - two.first_ = global_mutex; - - // Tell the token manager to be verbose when reporting deadlock. - ACE_Token_Manager::instance ()->debug (1); - - if (thr_mgr.spawn (ACE_THR_FUNC (two_token_thread), - (void *) &one, THR_BOUND) == -1) - ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "first spawn"), -1); - - if (thr_mgr.spawn (ACE_THR_FUNC (two_token_thread), - (void *) &two, THR_BOUND) == -1) - ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "second spawn"), -1); - - // Wait for all threads to exit. - thr_mgr.wait (); - - return 0; -} - -static int -rwlock_test (void) -{ - ACE_Thread_Manager thr_mgr; - - Two_Tokens reader1 (&thr_mgr); - Two_Tokens reader2 (&thr_mgr); - Two_Tokens reader3 (&thr_mgr); - Four_Tokens writer (&thr_mgr); - - if (remote_mutexes == 0) - { - reader1.first_ = new ACE_Local_RLock ("reader first", ignore_deadlock, 1); - reader1.second_ = new ACE_Local_RLock ("writer first 1", ignore_deadlock, 1); - reader2.first_ = new ACE_Local_RLock ("reader first", ignore_deadlock, 1); - reader2.second_ = new ACE_Local_RLock ("writer first 2", ignore_deadlock, 1); - reader3.first_ = new ACE_Local_RLock ("reader first", ignore_deadlock, 1); - reader3.second_ = new ACE_Local_RLock ("writer first 3", ignore_deadlock, 1); - - writer.first1_ = new ACE_Local_WLock ("writer first 1", ignore_deadlock, 1); - writer.first2_ = new ACE_Local_WLock ("writer first 2", ignore_deadlock, 1); - writer.first3_ = new ACE_Local_WLock ("writer first 3", ignore_deadlock, 1); - writer.second_ = new ACE_Local_WLock ("reader first", ignore_deadlock, 1); - } - else - { - ACE_Remote_Mutex::set_server_address (ACE_INET_Addr (server_port, server_host)); - - reader1.first_ = new ACE_Remote_RLock ("writer first 1", ignore_deadlock, 1); - reader1.second_ = new ACE_Remote_RLock ("reader first", ignore_deadlock, 1); - reader2.first_ = new ACE_Remote_RLock ("writer first 2", ignore_deadlock, 1); - reader2.second_ = new ACE_Remote_RLock ("reader first", ignore_deadlock, 1); - reader3.first_ = new ACE_Remote_RLock ("writer first 3", ignore_deadlock, 1); - reader3.second_ = new ACE_Remote_RLock ("reader first", ignore_deadlock, 1); - - writer.first1_ = new ACE_Remote_WLock ("writer first 1", ignore_deadlock, 1); - writer.first2_ = new ACE_Remote_WLock ("writer first 2", ignore_deadlock, 1); - writer.first3_ = new ACE_Remote_WLock ("writer first 3", ignore_deadlock, 1); - writer.second_ = new ACE_Remote_WLock ("reader first", ignore_deadlock, 1); - } - - // Tell the token manager to be verbose when reporting deadlock. - ACE_Token_Manager::instance ()->debug (1); - - if (thr_mgr.spawn (ACE_THR_FUNC (two_token_thread), - (void *) &reader1, THR_BOUND) == -1) - ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "first spawn"), -1); - - if (thr_mgr.spawn (ACE_THR_FUNC (two_token_thread), - (void *) &reader2, THR_BOUND) == -1) - ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "first spawn"), -1); - - if (thr_mgr.spawn (ACE_THR_FUNC (two_token_thread), - (void *) &reader3, THR_BOUND) == -1) - ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "first spawn"), -1); - - if (thr_mgr.spawn (ACE_THR_FUNC (run_writer), - (void *) &writer, THR_BOUND) == -1) - ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "second spawn"), -1); - - // Wait for all threads to exit. - thr_mgr.wait (); - - return 0; -} - -int -main (int argc, char* argv[]) -{ - if (parse_args (argc, argv) == -1) - return -1; - - if (rwlocks) - rwlock_test (); - else - mutex_test (); - - ACE_DEBUG ((LM_DEBUG, "test exiting.\n")); - return 0; -} -#else -int -main (int, char *[]) -{ - ACE_ERROR_RETURN ((LM_ERROR, - "threads not supported on this platform\n"), -1); -} -#endif /* ACE_HAS_THREADS */ |