/*
- * Copyright (c) 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2013, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <stdlib.h>
#include <unistd.h>
#include "compiler.h"
+#include "fatal-signal.h"
#include "hash.h"
#include "list.h"
#include "netdev-dpdk.h"
/* The order of the following calls is important, because
* ovsrcu_quiesce_end() saves a copy of the thread name. */
- set_subprogram_name("%s%u", aux.name, id);
+ char *subprogram_name = xasprintf("%s%u", aux.name, id);
+ set_subprogram_name(subprogram_name);
+ free(subprogram_name);
ovsrcu_quiesce_end();
- thread_set_nonpmd();
-
return aux.start(aux.arg);
}
free(slots);
}
+/* Cancels the callback to ovsthread_key_destruct__().
+ *
+ * Cancelling the call to the destructor during the main thread exit
+ * is needed while using pthreads-win32 library in Windows. It has been
+ * observed that in pthreads-win32, a call to the destructor during
+ * main thread exit causes undefined behavior. */
+static void
+ovsthread_cancel_ovsthread_key_destruct__(void *aux OVS_UNUSED)
+{
+ pthread_setspecific(tsd_key, NULL);
+}
+
/* Initializes '*keyp' as a thread-specific data key. The data items are
* initially null in all threads.
*
if (ovsthread_once_start(&once)) {
xpthread_key_create(&tsd_key, ovsthread_key_destruct__);
+ fatal_signal_add_hook(ovsthread_cancel_ovsthread_key_destruct__,
+ NULL, NULL, true);
ovsthread_once_done(&once);
}