void vTaskGetRunTimeStats( signed char *pcWriteBuffer )\r
        {\r
        unsigned portBASE_TYPE uxQueue;\r
-       unsigned long ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
+       unsigned long ulTotalRunTime;\r
 \r
+               /* A critical section is used because portGET_RUN_TIME_COUNTER_VALUE()\r
+               is implemented differently on different ports, so its not known if a\r
+               critical section is needed or not. */\r
+               taskENTER_CRITICAL();\r
+               {\r
+                       ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
+               }\r
+               taskEXIT_CRITICAL();\r
+       \r
                /* This is a VERY costly function that should be used for debug only.\r
                It leaves interrupts disabled for a LONG time. */\r
 \r