summaryrefslogtreecommitdiff
path: root/rts/Task.c
diff options
context:
space:
mode:
Diffstat (limited to 'rts/Task.c')
-rw-r--r--rts/Task.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/rts/Task.c b/rts/Task.c
index 4376148c7a..ac86311844 100644
--- a/rts/Task.c
+++ b/rts/Task.c
@@ -19,6 +19,8 @@
#include "Hash.h"
#include "Trace.h"
+#include <string.h>
+
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
@@ -197,6 +199,7 @@ freeTask (Task *task)
stgFree(task);
}
+/* Must take all_tasks_mutex */
static Task*
newTask (bool worker)
{
@@ -413,7 +416,7 @@ workerTaskStop (Task *task)
#if defined(THREADED_RTS)
-static void OSThreadProcAttr
+static void* OSThreadProcAttr
workerStart(Task *task)
{
Capability *cap;
@@ -439,8 +442,11 @@ workerStart(Task *task)
traceTaskCreate(task, cap);
scheduleWorker(cap,task);
+
+ return NULL;
}
+/* N.B. must take all_tasks_mutex */
void
startWorkerTask (Capability *cap)
{
@@ -468,7 +474,26 @@ startWorkerTask (Capability *cap)
ASSERT_LOCK_HELD(&cap->lock);
cap->running_task = task;
- r = createOSThread(&tid, "ghc_worker", (OSThreadProc*)workerStart, task);
+ // Set the name of the worker thread to the original process name followed by
+ // ":w", but only if we're on Linux where the program_invocation_short_name
+ // global is available.
+#if defined(linux_HOST_OS)
+ size_t procname_len = strlen(program_invocation_short_name);
+ char worker_name[16];
+ // The kernel only allocates 16 bytes for thread names, so we truncate if the
+ // original name is too long. Process names go in another table that has more
+ // capacity.
+ if (procname_len >= 13) {
+ strncpy(worker_name, program_invocation_short_name, 13);
+ strcpy(worker_name + 13, ":w");
+ } else {
+ strcpy(worker_name, program_invocation_short_name);
+ strcpy(worker_name + procname_len, ":w");
+ }
+#else
+ char * worker_name = "ghc_worker";
+#endif
+ r = createOSThread(&tid, worker_name, (OSThreadProc*)workerStart, task);
if (r != 0) {
sysErrorBelch("failed to create OS thread");
stg_exit(EXIT_FAILURE);