Jamie Oliver's 'shame' as restaurant collapse left him wanting to 'hide away'
Scientists discover new cause of cancer that hits 10,000 Britons every year - diet mistake could be to blame
Woman is 'raped twice in one night on popular beach' as man appears in court accused of sex attacks
Hyperconverged infrastructure is so hot right now it needs liquid cooling
Hyperconverged infrastructure most often involves a collection of modest 2U servers powered by mid-range processors that aren’t particularly challenging to operate. But Lenovo’s new models packing Xeon 6 processors may need liquid cooling.…
CodeSOD: Tangled Up in Foo
DZ's tech lead is a doctor of computer science, and that doctor loves to write code. But you already know that "PhD" stands for "Piled high and deep", and that's true of the tech lead's clue.
For example, in C#:
private List<Foo> ExtractListForId(string id) { List<Foo> list = new List<Foo>(); lock (this) { var items = _foos.Where(f => f.Id == id).ToList(); foreach (var item in items) { list.Add(item); } } return list; }The purpose of this function is to find all the elements in a list where they have a matching ID. That's accomplished in one line: _foo.Where(f => f.Id == id). For some reason, the function goes through the extra step of iterating across the returned list and constructing a new one. There's no real good reason for this, though it does force LINQ to be eager- by default, the Where expression won't be evaluated until you check the results.
The lock is in there for thread safety, which hey- the enumerator returned by Where is not threadsafe, so that's not a useless thing to do there. But it's that lock which hints at the deeper WTF here: our PhD-having-tech-lead knows that adding threads ensures you're using more of the CPU, and they've thrown threads all over the place without any real sense to it. There's no clear data ownership of any given thread, which means everything is locked to hell and back, the whole thing frequently deadlocks, and it's impossible to debug.
It's taken days for DZ to get this much of a picture of what's going on in the code, and further untangling of this multithreaded pile of spaghetti is going to take many, many more days- and much, much more of DZ's sanity.
[Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.Wildly popular Essex tearoom expands with brand new 'stylish' takeaway deli
'Work from the office or you're gone', Farage tells county council workers
Boy, 15, sent home from school with headache has inoperable tumour
Gang of girls 'attack elderly man and woman' in separate incidents on train - as police release CCTV
All the Harry Potter stars making money off projects celebrating the work of JK Rowling despite publicly criticising her
Oasis fans have already lost £2m to ticket scams, major bank warns
Dunelm's 'stunning' stair runner that adds 'colour and character' for just £55
The truth about Blake Lively and Ryan Reynolds' 'affair' - and the link to sham lawsuit behind war with Justin Baldoni
Brady Bunch star reveals how she almost DIED while filming the iconic sitcom's pilot episode
Why movie fans are divided over 'best reviewed film of the decade'
IBM Will Catch A Piece Of The GenAI Wave With Next-Gen Systems
We don’t normally spend a lot of time writing about IBM mainframes, but these big iron systems drive a lot of transactions in the world – transactions flush with demographics and context that will feed into AI models – and will be doing native and integrated AI processing for the applications that push those applications. …
IBM Will Catch A Piece Of The GenAI Wave With Next-Gen Systems was written by Timothy Prickett Morgan at The Next Platform.