Ben Jeurissen wrote:
> Hello,
>
> I have to deal with the following issue in C++:
>
> Two threads are started from the main thread, both capturing images from
> a different firewire camera. Both threads take shots of 460800 bytes at
> a rate of 30 frames per second. This works fine, without frame loss, and
> I can display the two framestreams on screen.
>
> Now I would like to write these frames to my disk too (2 10000rpm in
> striping mode raid), but my first naive attempts (just writing the
> images to disk image by image), causes the fwrite()'s to block after a
> while. What appraoch is suitable for this kind of problem? Is there some
> sort of "pattern" for it? Some buffering strategy which avoids those
> blocks?
>
> (The images don't actually have to be saved as individual files on disk,
> they can be written in lager blocks and separated later (whitout having
> to worry about the 30 frames per second constraint).)
>
> Any advice greatly appreciated.
>
> Ben
Since you didn't specify the platform, I suggest you peruse over
at news:comp.arch.embedded or maybe something under
news:comp.arch.* which suits your platform better.
The underlying issue is a real-time speed issue. One component
is slower than another. The pattern to resolve this is called
"double buffering". One task fills a buffer while another
empties it. Sometimes, more than one buffer may be necessary
to resolve the speed issues. Many OSes use this technique
when "spooling" files to the printer.
In your case, see if your disk controller has any intelligence
or DMA available. The best idea is for you to give the disk
controller the start address and quantity of data, then let
it go. Have it interrupt you when it is finished. Let the
interrupt handler continually feed the disk controller when
there are buffers ready.
Now the C++ part (or perhaps getting closer). I suggest a
circular queue (a.k.a. ring buffer) of pointers to buffers.
Let the input task fill buffers then insert them into the
queue. The Disk task will feed the disk controller then
remove the pointers from the queue. Don't allocate any
memory during this process; all buffers should be allocated
during the initialization of your program.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book