diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-07-13 10:51:08 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-07-16 10:06:55 -0700 |
| commit | 3f40a08eab60df77dc61ae0350e59f36e8d0ed16 (patch) | |
| tree | 356c6c9700735caad96a1a3bd0b7ea079b67646e /tests/reqctx.c | |
| parent | 3715056cf6337d2692b6916739042cff5296761d (diff) | |
| download | nng-3f40a08eab60df77dc61ae0350e59f36e8d0ed16.tar.gz nng-3f40a08eab60df77dc61ae0350e59f36e8d0ed16.tar.bz2 nng-3f40a08eab60df77dc61ae0350e59f36e8d0ed16.zip | |
fixes #592 reqctx test has a race
Diffstat (limited to 'tests/reqctx.c')
| -rw-r--r-- | tests/reqctx.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/reqctx.c b/tests/reqctx.c index de9f1ef2..f8bb7611 100644 --- a/tests/reqctx.c +++ b/tests/reqctx.c @@ -23,6 +23,7 @@ static struct { nng_socket s; nng_msg * msg; int cnt; + nng_mtx * mtx; } rep_state; void @@ -31,9 +32,11 @@ rep_cb(void *notused) int rv; (void) notused; + nng_mtx_lock(rep_state.mtx); if (rep_state.state == START) { rep_state.state = RECV; nng_recv_aio(rep_state.s, rep_state.aio); + nng_mtx_unlock(rep_state.mtx); return; } if ((rv = nng_aio_result(rep_state.aio)) != 0) { @@ -41,6 +44,7 @@ rep_cb(void *notused) nng_msg_free(rep_state.msg); rep_state.msg = NULL; } + nng_mtx_unlock(rep_state.mtx); return; } switch (rep_state.state) { @@ -60,6 +64,7 @@ rep_cb(void *notused) rep_state.cnt++; break; } + nng_mtx_unlock(rep_state.mtx); } #define NCTX 1000 @@ -95,6 +100,7 @@ TestMain("REQ concurrent contexts", { Convey("We can use REQ contexts concurrently", { nng_socket req; + So(nng_mtx_alloc(&rep_state.mtx) == 0); So(nng_aio_alloc(&rep_state.aio, rep_cb, NULL) == 0); So(nng_rep_open(&rep_state.s) == 0); So(nng_req_open(&req) == 0); @@ -130,6 +136,7 @@ TestMain("REQ concurrent contexts", { nng_close(req); nng_close(rep_state.s); nng_aio_free(rep_state.aio); + nng_mtx_free(rep_state.mtx); }); So(nng_listen(rep_state.s, addr, NULL, 0) == 0); |
