+ test_compare(MEMCACHED_SUCCESS, memcached_pool_release(pool, mmc[0]));
+
+ test_true(memcached_pool_destroy(pool) == memc);
+
+ return TEST_SUCCESS;
+}
+
+struct test_pool_context_st {
+ volatile memcached_return_t rc;
+ memcached_pool_st* pool;
+ memcached_st* mmc;
+ sem_t _lock;
+
+ test_pool_context_st(memcached_pool_st *pool_arg, memcached_st *memc_arg):
+ rc(MEMCACHED_FAILURE),
+ pool(pool_arg),
+ mmc(memc_arg)
+ {
+ sem_init(&_lock, 0, 0);
+ }
+
+ void wait()
+ {
+ sem_wait(&_lock);
+ }
+
+ void release()
+ {
+ sem_post(&_lock);
+ }
+
+ ~test_pool_context_st()
+ {
+ sem_destroy(&_lock);
+ }
+};
+
+static void* connection_release(void *arg)
+{
+ test_pool_context_st *resource= static_cast<test_pool_context_st *>(arg);
+ assert(resource);
+ if (resource == NULL)
+ {
+ abort();
+ }
+
+ // Release all of the memc we are holding
+ resource->rc= memcached_pool_release(resource->pool, resource->mmc);
+ resource->release();
+
+ pthread_exit(arg);
+}
+
+static test_return_t connection_pool3_test(memcached_st *memc)
+{
+ memcached_pool_st* pool= memcached_pool_create(memc, 1, 1);
+ test_true(pool);
+
+ memcached_st *pool_memc;
+ {
+ memcached_return_t rc;
+ pool_memc= memcached_pool_fetch(pool, NULL, &rc);
+ test_compare(MEMCACHED_SUCCESS, rc);
+ test_true(pool_memc);
+ }
+
+ /*
+ @note This comment was written to describe what was believed to be the original authors intent.
+
+ This portion of the test creates a thread that will wait until told to free a memcached_st
+ that will be grabbed by the main thread.
+
+ It is believed that this tests whether or not we are handling ownership correctly.
+ */
+ pthread_t tid;
+ test_pool_context_st item(pool, pool_memc);
+
+ test_zero(pthread_create(&tid, NULL, connection_release, &item));
+ item.wait();
+
+ memcached_return_t rc;
+ memcached_st *pop_memc;
+ int counter= 5;
+ do
+ {
+ struct timespec relative_time= { 0, 0 };
+ pop_memc= memcached_pool_fetch(pool, &relative_time, &rc);
+
+ if (memcached_failed(rc))
+ {
+ test_null(pop_memc);
+ }
+ } while (rc == MEMCACHED_TIMEOUT and --counter);
+
+ if (memcached_failed(rc)) // Cleanup thread since we will exit once we test.
+ {
+ pthread_join(tid, NULL);
+ test_compare(MEMCACHED_SUCCESS, rc);
+ }
+
+ {
+ int pthread_ret= pthread_join(tid, NULL);
+ test_true(pthread_ret == 0 or pthread_ret == ESRCH);
+ }
+ test_compare(MEMCACHED_SUCCESS, rc);
+ test_true(pool_memc == pop_memc);