Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use khash in a new thread #22

Closed
kellabyte opened this issue Aug 10, 2013 · 2 comments
Closed

How to use khash in a new thread #22

kellabyte opened this issue Aug 10, 2013 · 2 comments

Comments

@kellabyte
Copy link

I'm not looking for locking or a lock-free implementation of khash (although that would be nice!)

I hate it declared as this at the top of the .c file:

KHASH_MAP_INIT_STR(string_hashmap, hw_route_entry*)

In the .h file I have this:

extern void* routes;

Later on I spawn a new thread, and inside the new thread I do the following

void set_route(void* hashmap, char* name, hw_route_entry* route_entry)
{
    routes = kh_init(string_hashmap);
    int ret;
    khiter_t k;
    khash_t(string_hashmap) *h = hashmap;
    k = kh_put(string_hashmap, h, strdup(name), &ret);
    kh_value(h, k) = route_entry;
}

The kh_put() call segfaults with the following:

Program received signal SIGSEGV, Segmentation fault.
0x000000000041a390 in __ac_X31_hash_string (s=0xffffffffb0000950 <Address 0xffffffffb0000950 out of bounds>)
    at lib/haywire/src/haywire/khash.h:387
387     khint_t h = (khint_t)*s;
(gdb) bt
#0  0x000000000041a390 in __ac_X31_hash_string (s=0xffffffffb0000950 <Address 0xffffffffb0000950 out of bounds>)
    at lib/haywire/src/haywire/khash.h:387
#1  0x000000000041aa48 in kh_put_string_hashmap (h=0x7fffb0000920, 
    key=0xffffffffb0000950 <Address 0xffffffffb0000950 out of bounds>, ret=0x7fffb83e1dd8)
    at lib/haywire/src/haywire/http_server.c:34

I'm pretty new to C, is there something I need to do to make this work in a separate thread? It works fine if I don't use a thread. I'm not sure why there's a problem because I'm calling all the khash methods mentioned above in the same thread.

Any help would be greatly appreciated :)

@kellabyte
Copy link
Author

Upon some further review I found the problem and it was outside of khash. The error was leading me down the wrong assumption. Please close this :)

Thank you for a wonderful library.

@lh3
Copy link
Collaborator

lh3 commented Aug 12, 2013

Thank you for your head up and sorry for my late response.

@lh3 lh3 closed this as completed Aug 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants