syncrhonize access to a pool of files...need idea..! 
Author Message
 syncrhonize access to a pool of files...need idea..!

Hi
I have a thumbnail control which display several images ,and images
generator.
sometimes both the thumbnail and the generator access the same image
(one read,one write)

i am looking for an efficient way to synchronize the access

since i am using win95/win98 i cant use LockFileEx
my first idea is to create a mutex using the name of the file(it is a unique
name)

any one have better idea..?

thanks

tomer



Sun, 30 Mar 2003 03:00:00 GMT  
 syncrhonize access to a pool of files...need idea..!
You could solve this problem like this:

On reader side (thumbnail control):
    For opening the file use CreateFile() with the sharing parameter set to
FILE_SHARE_READ.
On writer side (generator):
    For opening the file use CreateFile() with the sharing parameter set to
0.

If the reader encounters a file currently used by the writer, CreateFile
will return INVALID_HANDLE_VALUE. If calling GetLastError() yields
ERROR_SHARING_VIOLATION, you could retry until you have success or the error
code differs from ERROR_SHARING_VIOLATION. Better: Store the files which
yield sharing violations in a list, and process them later. Same method for
the writer.

This works out fine for me.



Quote:
> Hi
> I have a thumbnail control which display several images ,and images
> generator.
> sometimes both the thumbnail and the generator access the same image
> (one read,one write)

> i am looking for an efficient way to synchronize the access

> since i am using win95/win98 i cant use LockFileEx
> my first idea is to create a mutex using the name of the file(it is a
unique
> name)

> any one have better idea..?

> thanks

> tomer



Sun, 30 Mar 2003 03:00:00 GMT  
 syncrhonize access to a pool of files...need idea..!
Klaus idea also struck me as the simplest and most elegant way to do it
(using share violations), but if you want synchronisation such that the
reader should refresh the thumbnails after a rewrite, you might want to
register messages and use SendMessage with HWND_BROADCAST to broadcast that
something is modified from the writer. The reader will then, of course, have
to handle this message and recreate the thumbnails.

Johan Rosengren
Responsable Informatique
PACTA S.A.


Quote:
> You could solve this problem like this:

> On reader side (thumbnail control):
>     For opening the file use CreateFile() with the sharing parameter set
to
> FILE_SHARE_READ.
> On writer side (generator):
>     For opening the file use CreateFile() with the sharing parameter set
to
> 0.

> If the reader encounters a file currently used by the writer, CreateFile
> will return INVALID_HANDLE_VALUE. If calling GetLastError() yields
> ERROR_SHARING_VIOLATION, you could retry until you have success or the
error
> code differs from ERROR_SHARING_VIOLATION. Better: Store the files which
> yield sharing violations in a list, and process them later. Same method
for
> the writer.

> This works out fine for me.



> > Hi
> > I have a thumbnail control which display several images ,and images
> > generator.
> > sometimes both the thumbnail and the generator access the same image
> > (one read,one write)

> > i am looking for an efficient way to synchronize the access

> > since i am using win95/win98 i cant use LockFileEx
> > my first idea is to create a mutex using the name of the file(it is a
> unique
> > name)

> > any one have better idea..?

> > thanks

> > tomer



Sun, 30 Mar 2003 03:00:00 GMT  
 syncrhonize access to a pool of files...need idea..!

Quote:
> I have a thumbnail control which display several images ,and images generator.
> sometimes both the thumbnail and the generator access the same image (one
> read,one write)
> i am looking for an efficient way to synchronize the access
> since i am using win95/win98 i cant use LockFileEx my first idea is to create
> a mutex using the name of the file(it is a unique name)

> any one have better idea..?

    Depending on the nature of the applications, I think Mutex would be the
best.
    Even better, make an unnamed mutex, it won't hurt.

--
Regards, Dejan M. CEO Alfa Co. http://www.alfaunits.co.yu and www.register.co.yu


Professional file&system related components and libraries for Win32 developers.
Alfa Units - #1 file and system handling units for Delphi.
Alfa File Monitor - #1 file monitoring system for Win32 developers.
Alfa Interceptor - #1 file protection and hiding system for Win32 developers.



Sun, 30 Mar 2003 03:00:00 GMT  
 syncrhonize access to a pool of files...need idea..!

Quote:
> Klaus idea also struck me as the simplest and most elegant way to do it (using
> share violations), but if you want synchronisation such that the reader should
> refresh the thumbnails after a rewrite, you might want to register messages
> and use SendMessage with HWND_BROADCAST to broadcast that something is
> modified from the writer. The reader will then, of course, have to handle this
> message and recreate the thumbnails.

    A very good idea, in my opinion!
    If You are a Delphi programmer, there are many classes that can help You.

--
Regards, Dejan M. CEO Alfa Co. http://www.alfaunits.co.yu and www.register.co.yu


Professional file&system related components and libraries for Win32 developers.
Alfa Units - #1 file and system handling units for Delphi.
Alfa File Monitor - #1 file monitoring system for Win32 developers.
Alfa Interceptor - #1 file protection and hiding system for Win32 developers.



Sun, 30 Mar 2003 03:00:00 GMT  
 syncrhonize access to a pool of files...need idea..!
Quote:
>     If You are a Delphi programmer, there are many classes that can help

You.

If you are a MFC programmer, there are many, too.



Quote:
> > Klaus idea also struck me as the simplest and most elegant way to do it
(using
> > share violations), but if you want synchronisation such that the reader
should
> > refresh the thumbnails after a rewrite, you might want to register
messages
> > and use SendMessage with HWND_BROADCAST to broadcast that something is
> > modified from the writer. The reader will then, of course, have to
handle this
> > message and recreate the thumbnails.

>     A very good idea, in my opinion!
>     If You are a Delphi programmer, there are many classes that can help
You.

> --
> Regards, Dejan M. CEO Alfa Co. http://www.alfaunits.co.yu and
www.register.co.yu


> Professional file&system related components and libraries for Win32
developers.
> Alfa Units - #1 file and system handling units for Delphi.
> Alfa File Monitor - #1 file monitoring system for Win32 developers.
> Alfa Interceptor - #1 file protection and hiding system for Win32
developers.



Mon, 31 Mar 2003 11:17:17 GMT  
 syncrhonize access to a pool of files...need idea..!

IPC via NamedPipes is a very nice approach and avoids message-broadcasting,
but is a little more complicated.



Quote:
> Klaus idea also struck me as the simplest and most elegant way to do it
> (using share violations), but if you want synchronisation such that the
> reader should refresh the thumbnails after a rewrite, you might want to
> register messages and use SendMessage with HWND_BROADCAST to broadcast
that
> something is modified from the writer. The reader will then, of course,
have
> to handle this message and recreate the thumbnails.

> Johan Rosengren
> Responsable Informatique
> PACTA S.A.



> > You could solve this problem like this:

> > On reader side (thumbnail control):
> >     For opening the file use CreateFile() with the sharing parameter set
> to
> > FILE_SHARE_READ.
> > On writer side (generator):
> >     For opening the file use CreateFile() with the sharing parameter set
> to
> > 0.

> > If the reader encounters a file currently used by the writer, CreateFile
> > will return INVALID_HANDLE_VALUE. If calling GetLastError() yields
> > ERROR_SHARING_VIOLATION, you could retry until you have success or the
> error
> > code differs from ERROR_SHARING_VIOLATION. Better: Store the files which
> > yield sharing violations in a list, and process them later. Same method
> for
> > the writer.

> > This works out fine for me.



> > > Hi
> > > I have a thumbnail control which display several images ,and images
> > > generator.
> > > sometimes both the thumbnail and the generator access the same image
> > > (one read,one write)

> > > i am looking for an efficient way to synchronize the access

> > > since i am using win95/win98 i cant use LockFileEx
> > > my first idea is to create a mutex using the name of the file(it is a
> > unique
> > > name)

> > > any one have better idea..?

> > > thanks

> > > tomer



Mon, 31 Mar 2003 11:21:57 GMT  
 syncrhonize access to a pool of files...need idea..!

Quote:
> If you are a MFC programmer, there are many, too.

    Any wrapper functions around for plain C?

--
Regards, Dejan M. CEO Alfa Co. http://www.alfaunits.co.yu and
www.register.co.yu

Professional file&system related components and libraries for Win32 developers.

Alfa Units - #1 file and system handling units for Delphi.
Alfa File Monitor - #1 file monitoring system for Win32 developers.
Alfa Interceptor - #1 file protection and hiding system for Win32 developers.



Mon, 31 Mar 2003 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. syncrhonize access to a pool of files...need idea..!

2. OleDB Resource pooling Vs. ODBC Connection pooling

3. My exe file needs to access files at an FTP site

4. Thread Pool Deadlock -- need help!

5. Need tutorial to create object that can be pooled in Com+

6. need advice on connection pooling approach

7. Data Access Layer in COM Server = Good Idea?

8. Looking for ideas: Access style reports

9. Still need help with this - Random Access File program

10. Need help access file date times, and looping via month/years

11. need a c libraries to access native dBase files

12. HELP, need C library to access FoxPro files

 

 
Powered by phpBB® Forum Software