about critical section

Discussion in 'Ruby' started by Difei Zhao, Sep 5, 2008.

  1. Difei Zhao

    Difei Zhao Guest

    Greetings all,

    I post a similar message to rails mailing list since I encountered
    this problem during development of a rails application, but now the
    problem is more ruby specific, so I decided to post here.

    Basically, I have to implement a critical section like this to avoid
    race condition:

    /* begin critical section */
    loop do
    filename = generate_filename
    break unless File.exist?(filename)
    end
    File.new(filename).flock
    /* end */
    write_to_filename

    Somebody said I could open a file with exclusive lock, but I do not
    know an atomic way. Could anyone help? Thanks alot!

    Difei
    --
    Posted via http://www.ruby-forum.com/.
    Difei Zhao, Sep 5, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob Barrows
    Replies:
    0
    Views:
    392
    Bob Barrows
    Feb 27, 2004
  2. =?Utf-8?B?Q2hyaXN0aWFu?=

    Critical section in WebForms

    =?Utf-8?B?Q2hyaXN0aWFu?=, Oct 7, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,590
    =?Utf-8?B?dG9tIHdpc25vd3NraQ==?=
    Oct 8, 2004
  3. James Hunter Ross

    IISState output, hung on critical section?

    James Hunter Ross, Nov 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,832
    Bruce Barker
    Nov 8, 2005
  4. Dave Brueck
    Replies:
    2
    Views:
    468
    Skip Montanaro
    Sep 19, 2003
  5. aeromarine
    Replies:
    15
    Views:
    1,465
    Martin
    Feb 18, 2008
Loading...

Share This Page