My previous mail got truncated, the completed listing is below:
Hi,
I have the following piece of code that is generating the above assertion. Could someone tell me what is going wrong:
template <typename T>
struct my_node_t : public avl_set_base_hook<> {
my_node_t(T data): m_data(data) {}
template <typename U>
friend bool operator< (const my_node_t<U>& lhs, const my_node_t<U>& rhs) {
return lhs.m_data < rhs.m_data;
};
T m_data;
};
typedef my_node_t<int> avlnode_t;
typedef avltree<avlnode_t> avltree_t;
struct args_t {
unsigned int seed[MAX_THREADS];
vector<avlnode_t>* items;
avltree_t* tree_ptr;
thread_args_t(size_t num_threads,
avltree_t* map,
vector<avlnode_t>* init_vec,
size_t num_entries,
unsigned int s) {
num_items = num_entries;
tree_ptr = map;
initial_items = init_vec;
for (size_t i = 0; i < num_threads; ++i) {
seed[i] = i + s;
}
for (int i = 0; i < 10; ++i) {
initial_items->push_back(i * 100);
}
for (vector<avlnode_t>::iterator it = initial_items->begin(); it != initial_items->end(); ++it) {
tree_ptr->insert_equal(*it);
}
}
~thread_args_t() {
tree_ptr->clear();
delete tree_ptr;
delete initial_items;
}
};
void worker(void* args_ptr) {
args_t* args = static_cast<args_t*>(args_ptr);
avltree_t* tree = args->tree_ptr;
vector<avlnode_t>* values = args->initial_items;
int index = 5; //generate_random<int>(my_seed, 0, num_items + 1)))
avlnode_t& find_element = *(values->begin() + index);
tree->insert_equal(find_element);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <-raises exception
}
int main() {
int num_threads = 1, num_entries = 10;
vector<avlnode_t>* init_vec = new vector<avlnode_t>;
avltree_t* tree = new avltree_t;
args_t* args = new args_t(num_threads, tree, init_vec, num_entries); worker(args); delete args; }
|