Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411279 Posts in 69323 Topics- by 58380 Members - Latest Member: bob1029

March 28, 2024, 02:23:56 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Task based multi-threading in .NET
Pages: [1]
Print
Author Topic: Task based multi-threading in .NET  (Read 1124 times)
Layl
Level 3
***

professional jerkface


View Profile WWW
« on: March 19, 2015, 06:45:14 AM »

I'm trying to work out a way to approach multi-threading in my game engine and have decided to go for Task based threading. I've got a few different directions I could go and I would like to see if anyone tried some of them before and what their experience with it was.

I am considering the following directions:

- Implement my own thread pool and work queue
- Use System.Threading.ThreadPool
- Use async/await keywords in C#, along with Task<>

It seems to be like the last one is the best one code quality wise, but I'm concerned about the overhead, as it seems in .NET these are designed for tasks that may take a few seconds rather than a millisecond.
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #1 on: March 19, 2015, 07:08:30 AM »

I havent run into any issues like that using the Task system.
Logged

Lavesson
Level 0
***


View Profile WWW
« Reply #2 on: March 21, 2015, 07:00:58 PM »

Implementing your own threadpool will probably mean more work than it's worth. To be honest, from what I've seen of the thread pool in .Net, it's actually a pretty damn good implementation. I'm not sure you could meaningfully implement anything better in a reasonable timespan.

Tasks aren't really necessarily only meant for things that may take a few seconds. Really, a task is just an abstraction. A task is something you want done as an asynchronous operation, whereas a thread is a way to perform the task.

If the TPL actually needs a thread, it's still going to use the thread pool, so you won't have to worry about the overhead of constantly creating/destroying threads. I don't think you should run into any problems with the task-based approach Smiley
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic