Chris Donnan : Programming – Brooklyn Style
software, trading, family, fun
Posted programming on Sunday, January 28th, 2007.
Periodic Table of Visualization Methods
You can leave a response, or trackback from your own site.
Posted .net, c#, java, programming on Saturday, January 27th, 2007.
I have had several chats with software developers lately that were working hard to use locking to perform some task. In each of these conversations, the simple solution was to use signaling, not just locking semantics.
I have found over time that for some reason, software developers all know about lock semantics. This has many varieties, lock keyword in C# (really a Monitor usage), Monitor.Enter, java synchronized, java ReentrantLock, etc, Mutexes, etc. The point of locking semantics is to mark a bit of code as a ‘critical section’ or a section that requires exclusive access to it – 1 thread or process at a time. There are varieties like Read/ Write locks, etc – but it is all essentially the same for lock semantics.
Lock/ synchronized/ critical section behavior is certainly mandatory, however as they say “when all you have is a hammer, everything is a nail”. Locks are not THE ONLY tool you can use to accomplish more complex multi-threaded goals. Signaling is another KEY set of abstractions that exists in java, .net, pthreads, Win32, etc, etc.
In java, all objects have signal and wait, in .net there are several choices, Monitor.Wait/ Monitor.Pulse, AutoResetEvents, ManualResetEvents, etc. Signals are used to communicate between concurrently executing threads.
I often ask developers in interviews to implement a blocking queue. Basically – what I am looking for is to see if they understand signaling. A simple blocking queue allows 1 thread to enqueue freely, and another thread to dequeue as long as there is at least 1 object to dequeue. If there is NO object to deque – the caller should be blocked. Signalling is the correct solution. People try to do Thread.Sleep, or say something like while ( _queue.Count > o) – both of which generally are not the best solution. There are plenty of more elaborate solutions – but here is a simple example.
class BlockingQueue< T >
{
Queue< T > _queue = new Queue< T >();
object _queueSync = new object();void Enqueue(T value)
{
lock(_queueSync)
{
_queue.Enqueue(value);
Monitor.Pulse(_queueSync);
}
}T Dequeue()
{
lock(_queueSync)
{
if( _queue.Count < 1)
Monitor.Wiat(_queueSync);return _queue.Dequeue()
}
}
}
(PS Blog software killed some >’s and <'s in the code -sorry I am too lazy to fiddle)
This is a very simple signaling example. WaitHandles, Auto/Manual Reset Events are related – and allow you to accomplish all the more complex inter-thread communication. There are still other ‘higher level’ abstractions like Condition Variables, Latches and the like. I encourage EVERY developer to absolutely get more intimate with these constructs. It is SO common to have poor threading code because developers do not know the tools provided, and when to apply them. It is MUCH easier to use a countdown latch construct than to jury rig some interweaving of thread joins or locks etc. The 1.5 JDK now incorporates some of the very best constructs – read into them -use them if you are writing java. .Net also has lots of excellent constructs. Get beyond locks and your code will get simpler and it will actually work !
-Chris
You can leave a response, or trackback from your own site.
Posted .net, programming on Saturday, January 13th, 2007.
Wow – this is great. Native CLR add-in model. How many ‘plug in’ models have we all seen? 50, 100? It seems they have even addressed isolation. The worst to use plug in models I have seen have forced appdomain seperation – thus making ALL plugins need to use remoting – blargh!!! I hope they have a better plan than that!
Eat it up!
Chris
You can leave a response, or trackback from your own site.
Posted programming on Tuesday, January 9th, 2007.
Jeremy is often writing posts after my own heart. This is yet-another-post that I would have written, if I had the time
I will send all my colleagues that I spout on about these concepts to this post.
-Chris
You can leave a response, or trackback from your own site.
Posted programming on Tuesday, January 9th, 2007.
Matt linked to this lovely Joshua Bloch presentation @ InfoQ I have found myself @Â InfoQ more and more – great work from the folks over there !
Also @ InfoQ- I often refer software developers to Eric Evans Domain Driven Design – great book. In any case – it is big book. InfoQ has this, a great summary of the major points of DDD – freely downloadable.
-Chris
You can leave a response, or trackback from your own site.
Posted non-techinical on Thursday, January 4th, 2007.
1) In the spirit of Marc’s post – music… I went to school for audio engineering, and for performance. I spent many years playing guitar for ~10 hrs/ day. I also spent WAY too much time in front of complex, cool audio gear
I studied classical and jazz for years on end (love that Latin influenced stuff most of all!)
2) I had a perm once – bad mistake – I cut that hair right off
In early high school – I thought I was in some bad glam band or something apparently.
3) The now infamous Scarlett Johansson is my friend Adrian’s sister
4) I have 3 tattoos – all ‘off the parlor wall generic’ and generally bad – 2 on my left arm – 1 on the right.
5) I used to make electronic music – I was on CDs with folks like Fatboy Slim, Frankie Bones, MeatBeat Manifesto and other somewhat eclectic electronic musicians.
5 people to blog tag…
Mike Roberts
Jeremy Miller
John Lemp
John Avery
Solomon Duskis
(PS – friends – not enough of you blog!)
-Chris
You can leave a response, or trackback from your own site.
Posted programming on Tuesday, January 2nd, 2007.
Hello – My name is Chris – and I am a book (and other information) addict. For the record, that includes audiobooks, books, magazines, stuff on the web, etc. In any case – I just wanted to share my manifold solution to my personal problem
1st – Speed – work on the raw speed of reading. Not too long ago - I started working on my speed reading. I suggest as a starter – this: Memletics Speed Reading Course. It works if you stick with it. I can say with certainty that my raw reading speed has vastly improved after maybe 2 months.
2nd – Audible premium listener club. $19.99/ month for 2 audiobooks. You can get 2 $100 books if you find em’ and want em’. Listen to your audiobooks slightly sped up on your ipod. Listen to audiobooks whenever you cannot hold something and read (subway sometimes, walking, at the gym, etc.)
3rd – Safari nobookshelf deal. $39.99/ month for just about all technical books ever – unlimited reading. Since I was spending ~$100/ month on tech books – this was a big saver! Diversity, info on demand, searchability… nice!
4th – Amazon Marketplace. It is easy. Find a book at Amazon. Find the people selling the same book used at the bottom of the page much cheaper. For a recent example – I got this book listed at Amazon for !$169 – for around $36!!! What a deal!
5th - Cash4books.net! Take your used books, put in their ISBN #s. Put your books in a box – they pay shipping. Get $ in your paypal account (transfer to your bank account from their).
6th – Citeseer - Scientific Literature Digital Library. Amazing, phenomenal resource for free! Without this resource, I would NEVER have been able to do any of the machine learning work I have done in the past several years!
 So – technical books – the lions share is taken care of via Safari – but the ones that are not – buy em (especially finance related books, machine learning books, etc.) . Some you keep as reference, some you will not need to – so you sell em’!
Citeseer is the 1st stop for any and all ‘white paper’ style research – use it!!!
I will also say - optionally you might choose the IEEE Digital Library and even some other great resources like any of the MIT Press Journals…. All great reading resources. They are more ‘niche’ and i use those types of resources for very specific needs, but I would say the best raw, complete, totally researched and explored resources are the journals.
Put all of this stuff together – and you can intake mass amounts of super information and do it economically !
-Chris
You can leave a response, or trackback from your own site.
Posted programming on Tuesday, January 2nd, 2007.
Gabe:Â
Micah:
Â
You can leave a response, or trackback from your own site.
