Is the CLR internally spawning a thread to respond to timer events?

Hans and I recently discussed the topic, and I'm curious how it really is implemented.

See the opening speech in the comments here: Are C # timers naturally multithreaded?

+1
source share
2 answers

Ok, I did some research ... Details in my post

In short, just a summary from there:

  • Regarding the SSCLI20, Hans was right. Theres a really separate thread for transmitting APC and timers. Thanks for your insistence, by the way. I got a chance to dig something interesting :)
  • In new systems, you can still implement without additional threads. I simply mistakenly believed that it was already there when CLR 2.0 was written. For more information, see CreateThreadpoolTimer, SetThreadpoolTimer, and CloseThreadpoolTimer.
+2
source

Based in the source source of .Net 4.0, System.Timers.Timer seems to use System.Threading.Timer to process the actual implementation data. The latter generates timers by calling AddTimerNative . AddTimerNative is an internal call.

Googling AddTimerNative produces many interesting results, including a comment by Willy Denoyette , where he claims that he calls CreateTimerQueueTimer .

This page states that "Callback functions are queued in the thread pool."

+2
source

Source: https://habr.com/ru/post/1442782/


All Articles