#include "test_util.h" #define NUM_THREADS 2 #define RUNTIME_SEC 10 static const char *const conn_config = "create"; typedef struct { WT_CONNECTION *conn; bool bulk; char *uri; } THREAD_ARGS; void *cursor_race(void *); int main(int argc, char *argv[]) { TEST_OPTS *opts, _opts; THREAD_ARGS t_args[NUM_THREADS]; WT_SESSION *session; pthread_t id[NUM_THREADS]; char tableconf[128]; int i; opts = &_opts; memset(opts, 0, sizeof(*opts)); testutil_check(testutil_parse_opts(argc, argv, opts)); testutil_recreate_dir(opts->home); testutil_check(wiredtiger_open(opts->home, NULL, conn_config, &opts->conn)); testutil_check(opts->conn->open_session(opts->conn, NULL, NULL, &session)); testutil_check(session->create(session, opts->uri, NULL)); memset(t_args, 0, sizeof(t_args)); for (i = 0; i < NUM_THREADS; ++i) { t_args[i].conn = opts->conn; t_args[i].uri = opts->uri; } t_args[0].bulk = false; t_args[1].bulk = true; for (i = 0; i < NUM_THREADS; ++i) testutil_check(pthread_create(&id[i], NULL, cursor_race, &t_args[i])); while (--i >= 0) testutil_check(pthread_join(id[i], NULL)); testutil_cleanup(opts); return (EXIT_SUCCESS); } /* * cursor_race -- * Opens a bulk or a classic cursor and close it on the same table over and over again. */ WT_THREAD_RET cursor_race(void *arg) { WT_CURSOR *cursor; WT_SESSION *session; THREAD_ARGS *threadargs; int ret; time_t now, start; threadargs = (THREAD_ARGS *)arg; (void)time(&start); (void)time(&now); testutil_check(threadargs->conn->open_session(threadargs->conn, NULL, NULL, &session)); while (difftime(now, start) < RUNTIME_SEC) { if (threadargs->bulk) ret = session->open_cursor(session, threadargs->uri, NULL, "bulk", &cursor); else ret = session->open_cursor(session, threadargs->uri, NULL, NULL, &cursor); if (ret == 0) testutil_check(cursor->close(cursor)); (void)time(&now); } return (NULL); }