These segfaults seem to be related to URI interning (raptor_avltree) using multiple pthreads.
Setting the RAPTOR_WORLD_FLAG_URI_INTERNING flag to 0 eliminates the segfaults from the previous example. // open world world = librdf_new_world(); librdf_world_open(world); // set raptor flags rworld = raptor_new_world(); raptor_world_set_flag(rworld, RAPTOR_WORLD_FLAG_URI_INTERNING, 0); librdf_world_set_raptor(world, rworld); Is it possible for raptor to use a pthread_mutex to synchronize the raptor_avltree function calls? It would be nice to have interning in a multi-threaded environment. Thanks! Anthony Bargnesi On Fri, Sep 19, 2014 at 4:16 PM, Anthony Bargnesi <[email protected]> wrote: > Hi folks, > > I am encountering segfaults when calling librdf_new_uri from multiple > threads in C. My program code: > > #include <stdio.h> > #include <stdlib.h> > #include <string.h> > #include <stdarg.h> > #include <pthread.h> > #include <librdf.h> > #include <raptor2.h> > /* pthread_mutex_t mutex; */ > > struct thread_struct { > librdf_world *world; > char *uri; > }; > > void *create_uri_instances(void *args) { > char *original_uri; > char *uri_copy; > librdf_uri *uri; > struct thread_struct *arg_struct = (struct thread_struct *) args; > const int iterations = 1000; > > librdf_world_open(arg_struct->world); > > int i; > for(i = 0; i < iterations; i++) { > uri_copy = (char *) malloc(strlen(arg_struct->uri) + 1); > strcpy(uri_copy, arg_struct->uri); > > /* pthread_mutex_lock(&mutex); */ > uri = librdf_new_uri(arg_struct->world, uri_copy); > librdf_free_uri(uri); > fprintf(stdout, "new/free of librdf_uri: %s\n", uri_copy); > free(uri_copy); > /* pthread_mutex_unlock(&mutex); */ > } > } > > int main(int argc, char *argv[]) { > librdf_world* world; > pthread_t create_uri_instances_thread_1; > pthread_t create_uri_instances_thread_2; > > // open world > world = librdf_new_world(); > librdf_world_open(world); > > /* pthread_mutex_init(&mutex, NULL); */ > > /* start thread 1 */ > struct thread_struct args1; > args1.world = world; > args1.uri = "http://host.org/1"; > pthread_create(&create_uri_instances_thread_1, NULL, > create_uri_instances, (void *) &args1); > > /* start thread 2 */ > struct thread_struct args2; > args2.world = world; > args2.uri = "http://host.org/2"; > pthread_create(&create_uri_instances_thread_2, NULL, > create_uri_instances, (void *) &args2); > > /* join on threads */ > pthread_join(create_uri_instances_thread_1, NULL); > pthread_join(create_uri_instances_thread_2, NULL); > > librdf_free_world(world); > pthread_mutex_destroy(&mutex); > return 0; > } > > Without the pthread mutex I encounter different segfaults originating from > raptor_avltree.c. The gdb backtraces are attached. When I synchronize > around librdf_new_uri / librdf_free_uri with the pthread mutext I do not > encounter segfaults. > > Is this expected behaviour? Does anyone have advice or examples on using > threads with librdf? > > Thanks for your time, > > Anthony Bargnesi > >
_______________________________________________ redland-dev mailing list [email protected] http://lists.librdf.org/mailman/listinfo/redland-dev
