External task threads - how do they work? #118
-
I'm having a hard time wrapping my head around how external task threads work. The examples mention file IO as an example. does registering an IO thread as an external task thread like that allow enkiTS to use the thread for other tasks when it's idle, or am I misunderstanding its purpose? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
External task threads can be used for a number of different use cases, their primary purpose is to allow the thread to use enkiTS, and for other threads to be able to add pinned tasks for that thread to run. The IO example is one such use case. IO access tends to be blocking, so if IO is done on a normal enkiTS thread it would prevent other work from being done - the number of active threads would be less than the number of CPU hardware threads (cores + hyperthreading). If we increase the number of enkiTS threads this would lead to oversubscription issues, so by creating an external thread which only checks for pinned tasks we can keep the number of active threads equal to the number of CPU hardware threads. For disk IO on modern SSDs this probably isn't that useful, but for network IO it is. So in this case you would not want enkiTS to use that thread when it's idle, since you should already have as many enkiTS threads (when including the main thread) as there are hardware threads. An alternative use case is when you don't control the active threads but want to perform tasking. For example you want to write a library which uses multithreading which might be used in Unreal Engine or Godot etc. You can have library users call a function Hope this makes sense, if not let me know. |
Beta Was this translation helpful? Give feedback.
Yes, unless you request a different number of enkiTS threads this is the default.
enkiTS does not create the external threads itself, this is something you need to do if you want to use them. This is why they are external threads.
No, this is somewhat complex and so I will add further explanations below.
A given system can only run as many software threads as th…