Hi all,<br><br>I am diving into the RTS, trying to identify where an OSThread is created and where it is destroyed (join). The idea is to read some hardware counters when it is just created and read them again when it is about to be destroyed (for the time being let&#39;s ignore, for the sake of understanding, the possibility of thread migration and context switches). Does anyone know where to place these reads?
<br><br>As shown in the code below, I tried &quot;printfing&quot; within &quot;workerStart&quot; (in the places where I thought I should read the counters), but it doesn&#39;t seem to print the same throughout several executions. I mean, running with -N2 and forking 2 Haskell threads (plus the main one), sometimes I get  three &quot;Scheduling&quot; and two &quot;Unscheduling&quot; and sometimes I get only one &quot;Unscheduling&quot; which discourages me about reading the counters there. Any clue about the reason?
<br>Probably &quot;workerStart&quot; is not the place to put it, I don&#39;t know. Any light thrown on it or any documentation to read would be welcome.<br><br>Cheers<br>Cristian Perfumo<br><br><br>void<br>workerStart(Task *task)
<br>{<br>&nbsp;&nbsp;&nbsp; Capability *cap;<br><br>&nbsp;&nbsp;&nbsp; // See startWorkerTask().<br>&nbsp;&nbsp;&nbsp; ACQUIRE_LOCK(&amp;task-&gt;lock);<br>&nbsp;&nbsp;&nbsp; cap = task-&gt;cap;<br>&nbsp;&nbsp;&nbsp; RELEASE_LOCK(&amp;task-&gt;lock);<br><br>&nbsp;&nbsp;&nbsp; // set the thread-local pointer to the Task:
<br>&nbsp;&nbsp;&nbsp; taskEnter(task);<br><br style="font-weight: bold;"><span style="font-weight: bold;">&nbsp;&nbsp;&nbsp; printf (&quot;Scheduling %p\n&quot;, task);</span><br>&nbsp;&nbsp;&nbsp; // schedule() runs without a lock.<br>&nbsp;&nbsp;&nbsp; cap = schedule(cap,task);
<br><br style="font-weight: bold;"><span style="font-weight: bold;">&nbsp;&nbsp;&nbsp; printf (&quot;Unscheduling %p\n&quot;, task);</span><br>&nbsp;&nbsp;&nbsp; // On exit from schedule(), we have a Capability.<br>&nbsp;&nbsp;&nbsp; releaseCapability(cap);<br>&nbsp;&nbsp;&nbsp; workerTaskStop(task);
<br>}<br><br>