mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 17:34:14 +08:00
mdbx: adds thread's cleanup test into mtest0.
Change-Id: I542425e5df1fb97d15030a681bc0e5173cf3c902
This commit is contained in:
parent
478b7f00d9
commit
1fa026f332
21
mtest0.c
21
mtest0.c
@ -23,6 +23,8 @@
|
||||
#include <sys/stat.h>
|
||||
#include "mdbx.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
|
||||
#define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
|
||||
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
|
||||
@ -32,6 +34,18 @@
|
||||
# define DBPATH "./testdb"
|
||||
#endif
|
||||
|
||||
void* thread_entry(void *ctx)
|
||||
{
|
||||
MDB_env *env = ctx;
|
||||
MDB_txn *txn;
|
||||
int rc;
|
||||
|
||||
E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
|
||||
mdb_txn_abort(txn);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc,char * argv[])
|
||||
{
|
||||
int i = 0, j = 0, rc;
|
||||
@ -60,7 +74,7 @@ int main(int argc,char * argv[])
|
||||
}
|
||||
|
||||
E(mdb_env_create(&env));
|
||||
E(mdb_env_set_maxreaders(env, 1));
|
||||
E(mdb_env_set_maxreaders(env, 42));
|
||||
E(mdb_env_set_mapsize(env, 10485760));
|
||||
|
||||
E(stat("/proc/self/exe", &exe_stat)?errno:0);
|
||||
@ -184,6 +198,11 @@ int main(int argc,char * argv[])
|
||||
mdb_cursor_close(cur2);
|
||||
E(mdb_txn_commit(txn));
|
||||
|
||||
for(i = 0; i < 41; ++i) {
|
||||
pthread_t thread;
|
||||
pthread_create(&thread, NULL, thread_entry, env);
|
||||
}
|
||||
|
||||
printf("Restarting cursor outside txn\n");
|
||||
E(mdb_txn_begin(env, NULL, 0, &txn));
|
||||
E(mdb_cursor_open(txn, dbi, &cursor));
|
||||
|
Loading…
x
Reference in New Issue
Block a user