Re: HASH_ADD_PTR causing the program to hang

41 views
Skip to first unread message

Jay

unread,
Aug 7, 2022, 1:05:05 PM8/7/22
to uth...@googlegroups.com
Oh there is a typo, that enc_dec_table should be ut_hash_table

On Sun, Aug 7, 2022 at 1:00 PM Jay <siber...@gmail.com> wrote:
Hello uthash group!

I just wanted to ask a question regarding the uthash where I am having an issue that by the frequent calling of the function which contains HASH_ADD_PTR  API seems to be hanging the program. 

For instance, I have a pseudo-code that looks like this:
typedef struct {
  char *key;      
  uint64_t val;  
  UT_hash_handle hh;  /* hashable structure */
} ut_table;
ut_table *hash = NULL;
char *uthash_example(char *addr) {
  ut_table *ut_hash_table;
  HASH_FIND_PTR(hash, &addr, ut_hash_table);
  if (enc_dec_table) {
    rand_key = ut_hash_table->val;
  }
  ut_hash_table->key = addr;
  ut_hash_table->val = rand_key;
  HASH_ADD_PTR(hash, key, ut_hash_table); // causes program to halt
  return addr;
}

This function gets called repeatedly throughout the program's execution, and if I comment out HASH_ADD_PTR    program works perfectly fine, but with it, it hangs the program.

After trying to fix it, my current guess is that I'm trying to add the key that already exists in the table. However, I haven't been able to resolve this issue, so I wanted to ask for any other possible explanation. Maybe instead of using a PTR as a key, I should use something else?

Jay

unread,
Aug 7, 2022, 2:38:14 PM8/7/22
to uth...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages