|
#include <smart_ptr.hpp>
#include "../smartptr/smart_ptr.hpp" #include "../smartptr/sync_wrapper.hpp" smart_ptr<mutex_wrapper<vector<int> >, copy_on_write_policy<ref_link_policy, intrusive_lock_policy> > SharedSmartPointer = new mutex_wrapper<vector<int> >; int ThreadIDIndex = 10; void example_intrusive_lock_policy_usage(void*) //example_intrusive_lock_policy_usage is a thread executed via _beginthread { const size_t MaxSizeAllowed = 2000000; int ThreadId = ThreadIDIndex++; int SleepTime = rand()% 30; int QtyToAdd = rand()% 1000; Sleep(SleepTime); for(;;) { int ValidateResults = 0; scope_lock MyLocked = SharedSmartPointer; size_t StartPos = SharedSmartPointer->size(); for(int i = 0;i < QtyToAdd;++i) { int AddValue = rand()% 9999; ValidateResults += AddValue; SharedSmartPointer->push_back(AddValue); } int ValidateResults_2nd = 0; for(int i = 0;i < QtyToAdd;++i) { ValidateResults_2nd += (*SharedSmartPointer)[StartPos + i]; } // cout << "ID("<< ThreadId << "): size = " << (int)SharedSmartPointer->size() << // " V1 = " << ValidateResults << " V2 = " << ValidateResults_2nd << endl; if (ValidateResults != ValidateResults_2nd) { cout << "ID("<< ThreadId << "): Error :" << " V1 = " << ValidateResults << " V2 = " << ValidateResults_2nd << endl; system("pause"); exit(-1); } if (SharedSmartPointer->size() > MaxSizeAllowed) { cout << "ThreadId(" << ThreadId << "): Clearing Vect, size = " << (int)SharedSmartPointer->size() << endl; SharedSmartPointer->clear(); } } } void Test_intrusive_lock_policy() { srand((unsigned) time(NULL)); const int QtyTestThreads = 20; cout << "Starting Synchronize Smart Pointer Test" << endl; for(int i = 0;i < QtyTestThreads;++i) _beginthread(example_intrusive_lock_policy_usage, 0, NULL); for(;;) Sleep(9000); }
Definition at line 704 of file smart_ptr.hpp.
Public Member Functions | |
intrusive_lock_policy () | |
template<class T_obj> | |
void | pointee_lock_policy (T_obj *p) |
template<class T_obj> | |
void | const_pointee_lock_policy (T_obj *p) |
template<class T_obj> | |
void | assignment_lock_policy (T_obj *p) |
template<class T_obj> | |
void | assignment_unlock_policy (T_obj *p) |
template<class T_obj> | |
void | destructor_lock_policy (T_obj *p) |
template<class T_obj> | |
void | destructor_unlock_policy (T_obj *p) |
template<class T_obj> | |
T_obj * | constructor_lock_policy (T_obj *p) |
template<class T_obj> | |
void | constructor_unlock_policy (T_obj *p) |
template<class T_obj> | |
void | lock (T_obj *p) |
template<class T_obj> | |
void | unlock (T_obj *p) |
template<class T_obj> | |
bool | trylock (T_obj *p) |
template<class T_obj> | |
bool | islock (T_obj *p) |