Shows how to access a database with multiple threads.
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <wiredtiger.h>
void *scan_thread(void *arg);
const char *home = "WT_TEST";
#define NUM_THREADS 10
void *
scan_thread(void *arg)
{
const char *key, *value;
int ret;
NULL, NULL, &cursor);
while ((ret = cursor->
next(cursor)) == 0) {
ret = cursor->
get_key(cursor, &key);
printf("Got record: %s : %s\n", key, value);
}
return (arg);
}
int
main(void)
{
pthread_t threads[NUM_THREADS];
int i, ret;
"create", &conn)) != 0)
fprintf(stderr, "Error connecting to %s: %s\n",
ret = session->
create(session,
"table:access",
"key_format=S,value_format=S");
ret = session->
open_cursor(session,
"table:access", NULL,
"overwrite", &cursor);
ret = session->
close(session, NULL);
for (i = 0; i < NUM_THREADS; i++)
ret = pthread_create(&threads[i], NULL, scan_thread, NULL);
for (i = 0; i < NUM_THREADS; i++)
ret = pthread_join(threads[i], NULL);
ret = conn->
close(conn, NULL);
return (ret);
}