[commit: ghc] master: Name worker threads using pthread_setname_np (674c631)
git at git.haskell.org
git at git.haskell.org
Fri Oct 10 13:32:05 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/674c631ea111233daa929ef63500d75ba0db8858/ghc
>---------------------------------------------------------------
commit 674c631ea111233daa929ef63500d75ba0db8858
Author: Simon Marlow <marlowsd at gmail.com>
Date: Fri Oct 10 14:26:19 2014 +0100
Name worker threads using pthread_setname_np
This helps identify threads in gdb particularly in processes with a
lot of threads.
>---------------------------------------------------------------
674c631ea111233daa929ef63500d75ba0db8858
includes/rts/OSThreads.h | 2 +-
rts/Task.c | 2 +-
rts/posix/OSThreads.c | 7 +++++--
rts/sm/GC.c | 17 +++++++++--------
rts/win32/OSThreads.c | 3 ++-
testsuite/tests/rts/testwsdeque.c | 2 +-
6 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/includes/rts/OSThreads.h b/includes/rts/OSThreads.h
index e99be8a..a3ed47c 100644
--- a/includes/rts/OSThreads.h
+++ b/includes/rts/OSThreads.h
@@ -171,7 +171,7 @@ extern void yieldThread ( void );
typedef void OSThreadProcAttr OSThreadProc(void *);
-extern int createOSThread ( OSThreadId* tid,
+extern int createOSThread ( OSThreadId* tid, char *name,
OSThreadProc *startProc, void *param);
extern rtsBool osThreadIsAlive ( OSThreadId id );
extern void interruptOSThread (OSThreadId id);
diff --git a/rts/Task.c b/rts/Task.c
index 0370711..42893fe 100644
--- a/rts/Task.c
+++ b/rts/Task.c
@@ -462,7 +462,7 @@ startWorkerTask (Capability *cap)
ASSERT_LOCK_HELD(&cap->lock);
cap->running_task = task;
- r = createOSThread(&tid, (OSThreadProc*)workerStart, task);
+ r = createOSThread(&tid, "ghc_worker", (OSThreadProc*)workerStart, task);
if (r != 0) {
sysErrorBelch("failed to create OS thread");
stg_exit(EXIT_FAILURE);
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index e627bab..e880b89 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -129,11 +129,14 @@ shutdownThread(void)
}
int
-createOSThread (OSThreadId* pId, OSThreadProc *startProc, void *param)
+createOSThread (OSThreadId* pId, char *name,
+ OSThreadProc *startProc, void *param)
{
int result = pthread_create(pId, NULL, (void *(*)(void *))startProc, param);
- if(!result)
+ if (!result) {
pthread_detach(*pId);
+ pthread_setname_np(*pId, name);
+ }
return result;
}
diff --git a/rts/sm/GC.c b/rts/sm/GC.c
index dabcd72..19d9ab2 100644
--- a/rts/sm/GC.c
+++ b/rts/sm/GC.c
@@ -670,6 +670,15 @@ GarbageCollect (nat collect_gen,
if (major_gc) { gcCAFs(); }
#endif
+ // Update the stable pointer hash table.
+ updateStableTables(major_gc);
+
+ // unlock the StablePtr table. Must be before scheduleFinalizers(),
+ // because a finalizer may call hs_free_fun_ptr() or
+ // hs_free_stable_ptr(), both of which access the StablePtr table.
+ stableUnlock();
+
+ // Must be after stableUnlock(), because it might free stable ptrs.
if (major_gc) {
checkUnload (gct->scavenged_static_objects);
}
@@ -696,14 +705,6 @@ GarbageCollect (nat collect_gen,
}
}
- // Update the stable pointer hash table.
- updateStableTables(major_gc);
-
- // unlock the StablePtr table. Must be before scheduleFinalizers(),
- // because a finalizer may call hs_free_fun_ptr() or
- // hs_free_stable_ptr(), both of which access the StablePtr table.
- stableUnlock();
-
// Start any pending finalizers. Must be after
// updateStableTables() and stableUnlock() (see #4221).
RELEASE_SM_LOCK;
diff --git a/rts/win32/OSThreads.c b/rts/win32/OSThreads.c
index e336bd2..c3d3af6 100644
--- a/rts/win32/OSThreads.c
+++ b/rts/win32/OSThreads.c
@@ -98,7 +98,8 @@ shutdownThread()
}
int
-createOSThread (OSThreadId* pId, OSThreadProc *startProc, void *param)
+createOSThread (OSThreadId* pId, char *name STG_UNUSED,
+ OSThreadProc *startProc, void *param)
{
HANDLE h;
h = CreateThread ( NULL, /* default security attributes */
diff --git a/testsuite/tests/rts/testwsdeque.c b/testsuite/tests/rts/testwsdeque.c
index 51aeec1..e6f644c 100644
--- a/testsuite/tests/rts/testwsdeque.c
+++ b/testsuite/tests/rts/testwsdeque.c
@@ -149,7 +149,7 @@ int main(int argc, char*argv[])
}
for (n=0; n < THREADS; n++) {
- createOSThread(&ids[n], thief, (void*)(StgWord)n);
+ createOSThread(&ids[n], "thief", thief, (void*)(StgWord)n);
}
for (n=0; n < SCRATCH_SIZE; n++) {
More information about the ghc-commits
mailing list