# About transaction do..end block (or critical section)

**URL:** <https://www.ruby-forum.com/t/about-transaction-do-end-block-or-critical-section/147731>\
**Category:** Deployment\
**Created:** [September 4, 2008, 7:21pm UTC](https://www.ruby-forum.com/t/about-transaction-do-end-block-or-critical-section/147731 "2008-09-04T19:21:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![difei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a4c791/32.png) [@difei](https://www.ruby-forum.com/u/difei)\
**Post date:** [September 4, 2008, 7:21pm UTC](https://www.ruby-forum.com/t/about-transaction-do-end-block-or-critical-section/147731/1 "2008-09-04T19:21:20Z")

</div>

Greetings all,

Does the transaction do…end block guaranteed a critical section or  
just a database transaction? I want to save some file to the file system  
and then save the file path to a DB table, there are race conditions  
because other rails process/thread may create a file with a same name  
and this application may destroy the file by overwrite it. I want to  
construct a critical section like:

/\* critical section do _/  
file\_path = generate\_filepath  
some\_process if file\_path.exist?  
dbrec1.file\_path = file\_path  
dbrec1.save  
dbrec2.save  
File.write(file\_path)  
/_ end \*/

How can I achieve this? Thanks very much!

Cheers
