ERROR: The requested URL could not be retrieved (yeah, site didn’t work when i clicked on it from RSS).
Matt uses this bit of ruby code to demonstrate that here you can’t ever not close the file handle:
File.open('something.txt') do |fd|
# Manipulate the file through 'fd'
end
# File handle is now closed
Which seems pretty cool. However, a good C++ programmer can also acheive the same (or better) things!
For example, in NDB (well, in the portability library we use inside NDB) we have a class called Guard. The constructor for Guard pthread_mutex_locks a mutex. The destructor unlocks it. So, for when you’ve got some simple mutual exclusion you need doing, you can have bits of code like this:
{
Guard g(m_config_mutex);
…
[Read more]