a synchronization issue - jusy for you guys

From: Amit (amit_t_at_chief.co.il)
Date: 06/06/04


Date: Sun, 6 Jun 2004 15:46:18 +0200

i have a number of worker threads, getting a file name when created and
doing some processing with that file. some of the threads might get the same
file name, and in that case i want the first one who got to it to "tell" all
the other ones with that same file to wait untill its done. When it is done,
i want the next thread to "lock" the file for itself and "release" it to
others when it is done, and so on... the reason im using "" is because i
want all synchronization to be external, and NOT by file locking mechanizm.

i tried the following in my worker threads:

  hEvent := OpenEvent(EVENT_ALL_ACCESS, True, PChar(FileName));
  if hEvent = 0 then // if no one is processing that same file
right now
  begin
    hEvent := CreateEvent(nil, True, False, PChar(FileName));
  end else // Someone is processing that file, wait until its done
  begin
    WaitForSingleObject(hEvent, INFINITE);
  end;
  ..
  .. { some processing }
  ..

  SetEvent(hEvent); // Tell others im done with that file
  CloseHandle(hEvent);

but it doesnt seem to work properly.
i need some kind of named critical section or something.
ideas?



Relevant Pages

  • Re: ThreadPool Questions
    ... You sould have an output data pool. ... Worker threads all continuously take data out of the queue, ... is good but you want less synchronization between threads. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Informing UI thread of target for sending messages?
    ... But now it seems worker threads would be better. ... And UI threads are still not a good choice; an I/O Completion Port ... cost of thread creation would be unnoticeable. ... the MFC synchronization primitves are crap and should be avoided. ...
    (microsoft.public.vc.mfc)
  • Re: adapter.fill and progress bar
    ... worker threads) are synchronized with the control backgroundworker is placed ... Thus you don't need any special synchronization. ... The same could be said for windows - why does windows use ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Sequential consitency on X86_64 - implementation of a bust wait algo not working inspite of
    ... here is a very simple distributed spin-wait barrier synchronization algorithm I have whipped up: ... void wait ... waits for all worker threads to hit the barrier ...
    (comp.arch)
  • Re: Informing UI thread of target for sending messages?
    ... Completion Port ... But now it seems worker threads would be better. ... The code is already fast enough for a single file, ... the MFC synchronization primitves are crap and should be avoided. ...
    (microsoft.public.vc.mfc)