Skip to content

Instantly share code, notes, and snippets.

@op
Last active December 17, 2015 16:49
Show Gist options
  • Save op/5641408 to your computer and use it in GitHub Desktop.
Save op/5641408 to your computer and use it in GitHub Desktop.
assert on mutex.c:71 triggered when closing socket in separate thread
#include "src/nn.h"
#include "src/reqrep.h"
#include "src/utils/err.c"
#include "src/utils/thread.c"
#include "src/utils/sleep.c"
#include <stddef.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
int rep;
void worker (void *arg)
{
int rc;
int i;
int timeo;
char buf[3];
/* We need to set timeout. Would be sweet not needing it on close. */
timeo = 10;
rc = nn_setsockopt(rep, NN_SOL_SOCKET, NN_RCVTIMEO, &timeo, sizeof(timeo));
assert(rc == 0);
for (i = 0; 1; i++) {
rc = nn_recv(rep, buf, 3, 0);
if (i == 0 && rc == 3) {
continue;
}
assert(rc < 0);
if (nn_errno() == EAGAIN)
continue;
else
assert(0);
}
}
int main(int argc, char *argv[])
{
int rc;
int req;
int timeo;
struct nn_thread thread;
req = nn_socket(AF_SP, NN_REQ);
assert(req != -1);
rc = nn_connect(req, "inproc://thread_recv_close");
assert(rc >= 0);
rep = nn_socket(AF_SP, NN_REP);
assert(rep != -1);
rc = nn_bind(rep, "inproc://thread_recv_close");
assert(rc >= 0);
rc = nn_send(req, "ABC", 3, 0);
assert(rc == 3);
/* Wait a bit till the worker thread blocks in nn_recv(). */
nn_thread_init(&thread, worker, NULL);
nn_sleep(100);
rc = nn_close(req);
assert(rc == 0);
rc = nn_close(rep);
assert(rc == 0);
nn_thread_term(&thread);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment