| Author |
Message |
|
| Radagast |
Posted: Mon Jan 30, 2012 2:12 pm |
|
|
|
Joined: 30 Jan 2012
Posts: 1
|
Hello!
What are the best approaches to use RAII (Resource allocation is initialization) idiom in Erlang at the level of a function scope or try-catch-after scope? in other words, how do I release resources automatically when execution leaves a function either normally or throwing an exception?
thanks in advance |
|
|
| Back to top |
|
| dehunter |
Posted: Mon Feb 06, 2012 9:37 am |
|
|
|
Joined: 23 Jun 2011
Posts: 1
|
You should have 2 processes for this. One is worker and second is "resource watcher". You can do all resource initializations in "resource watcher" and then run you worker process. Then when something fail in worker - you just do all deallocations in "resource watcher"(it will be notified when linked process die). Then resource watcher also dies.
But your "resource watcher" can also die in deallocation procedure.
But usual you can avoid all this - cos in erlang you have garbage collector.
If you have some hard initializations - try to review you architecture - maybe there are other way which will simplify things. |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|