As a first attempt to write an awaitable queue, the queue is unbounded. The producer side of the queue is then synchronous and we can concentrate on making consumer side awaitable. The code for the can be found at the end of this post.
Blog about fun in programming, bicycle building projects and my adventures in kayaking.
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
Thursday, April 12, 2012
Thursday, February 16, 2012
Locking Style for Concurrent Programs (c#)
As a job I do a lot of asynchronous programming. I have been working intensively with multi threading some 6 years now (before that I did programming on Unix in c++).
As a consequence of the problems I encountered during this 6 year period, the way I use locks has changed a lot. The most recurring problems were:
As a consequence of the problems I encountered during this 6 year period, the way I use locks has changed a lot. The most recurring problems were:
- deadlocks.
- pumping on the UI thread. When the UI-thread waits on a lock, the runtime can decide to start pumping on that call stack!!! This way *any* code can be called from nearly any point in your code. This can easily cause deadlocks or other (crazy) faulty programs because of unexpected reentry.
- performance: I used to take my locks over longer periods of time. For example during doing I/O or remoting to get some kind of serialization behavior. Instead it has shown to be a better idea to schedule work where possible, as it is often not important when something really happens.
Labels:
.net,
concurrency,
csharp,
locking,
programming,
style guide
Subscribe to:
Posts (Atom)