Exemple #1
0
 Reference& operator=(const Reference& rhs)
 {
     decrease_count();
     m_referenced = rhs.m_referenced;
     m_count = rhs.m_count;
     increase_count();
 }
Exemple #2
0
void* workerThread(void *resources){

  //Take the resource, make sure to access and check if there are enough
  do{
    //wait for access
    pthread_mutex_lock(&leMutex);
    //check status
    if((int)available_resources<(int)resources){
     //release mutex if there are not enough resources
     pthread_mutex_unlock(&leMutex);
    }
    else{
     //if there are enough resources use them
     decrease_count(resources);
     printf("Taking %d resources current count = %d\n",resources,available_resources);
     //release access to the resources
     pthread_mutex_unlock(&leMutex);
     break;
    }
  }while(1);

  //do that random sleep
  sleep(rand()%5);

  //Give the resources back, less strict because we are just returning.
  //wait for access
  pthread_mutex_lock(&leMutex);
  //recieve access to resources
  increase_count(resources);
  printf("Returning %d resources current count = %d\n",resources,available_resources);
  //release access to the resources
  pthread_mutex_unlock(&leMutex);

pthread_exit(NULL);
}
Exemple #3
0
    referenced<T, N> &operator=(const referenced<T, N> &copy) noexcept
    {
        decrease_count();

        this->iterator = copy.iterator;

        increase_count();

        return *this;
    }
Exemple #4
0
    ~referenced() noexcept
    {
        decrease_count();

        if (references->size() == 0)
        {
            delete references;

            references = nullptr;
        }
    }
void* thread_task(void* param) {
    int random = (int)(5*(rand()/(double)RAND_MAX) + 1);
    decrease_count(random);
    increase_count(random);
    pthread_exit(0);
}
Exemple #6
0
// Destructor. Frees memory after object is deleted.
String::~String()
{
	delete [] index;
	decrease_count(); // Decreases total object count.
}
Exemple #7
0
 ~Reference()
 {
     decrease_count();
 }