GSOC Week 9 (Partial) report
This week was revolving around the print debugging in the gccgo runtime in search for clues regarding the creation of new threads under the goruntime, so as to see if there is something wrong with the runtime itself, or the way the runtime interacts with the libpthread.
(partial presentation of) findings
During print debugging the gccgo runtime, I didn’t notice anything abnormal or
unusual so far. For example, the code that does trigger the assertion failure
seems to work at least once, since pthread_create()
returns 0
at least once.
This is expected behavior, since we already have stated that there is at least
one M
(kernel thread) created at the initialisation of the program’s runtime.
If however, we try to use a go statement in our program, to make usage of a goroutine, the runtime still fails at the usual assertion fail, however the output of the program is this:
root@debian:~/Software/Experiments/go# ./a.out
[DEBUG] pthread_create returned 0
a.out: ./pthread/pt-create.c:167: __pthread_create_internal: Assertion `({ mach_port_t ktid = __mach_thread_self (); int ok = thread->kernel_thread == ktid;
__mach_port_deallocate ((__mach_task_self + 0), ktid); ok; })' failed.
Aborted
The above output can give us some pieces of information:
pthread_create()
is called at least once.- it executes successfuly and without errors - libpthread code suggests that 0 is returned upon successful execution and creation of a thread
- However the assertion is still triggered, which we know it’s getting triggered during thread creation.
The second bullet point is also being supported by the fact that even if you exe cute something as simple as hello world in go, a new M is created, so you get something along the lines of this as an output:
There is however something that the above piece of code doesn’t tell us, but it would be useful to know: How many times did we create a new thread? So we modify our gcc’s source code to see how many times the runtimes attempts to create a new kernel thread (M). This is what we get out of it:
root@debian:~/Software/Experiments/go# ./a.out
[DEBUG] Preparing to create a new thread.
[DEBUG] pthread_create returned 0
a.out: ./pthread/pt-create.c:167: __pthread_create_internal: Assertion `({ mach_port_t ktid = __mach_thread_self (); int ok = thread->kernel_thread == ktid;
__mach_port_deallocate ((__mach_task_self + 0), ktid); ok; })' failed.
[DEBUG] Preparing to create a new thread.
aborted.
The code at this point in the runtime is this:
We can deduce two things about our situation right now:
- There is at least one thread successfully created, and there is an attempt to create another one.
- The second time, there is a failure before pthread_create is called.
Continuation of work.
I have been following this course of path the last week. I presented some of my findings, and hope to soon be able to write an exhaustive report on what exactly it is that causes the bug.