Многопоточность и общий ресурс: периодическое копирование данных из буфера (структуры данных) в файл с использованием C+C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Многопоточность и общий ресурс: периодическое копирование данных из буфера (структуры данных) в файл с использованием C+

Сообщение Anonymous »


My code has a data structure say for example "vector of vector of Strings. I've 2 threads:

Thread 1 is writing data to this data structure (buffer in RAM).

Thread 2 running in parallel which should copy data FROM the above buffer i.e data structure TO a file for every "x" milliseconds.

I'm wondering how would I achieve this in C++ ? It should consider key points in problem statement like:
  • The copy from buffer to file should happen only once in "X" milliseconds.
  • Synchronization between both threads.

EDITING THE QUERY WITH MORE DETAILS PER THE ASK

I want to build a library (*.lib) & this library exposes some APIs hence it gets input data from EXE or any entity which uses my library through these APIs.

Say the data received by my library is in the form of a vector of strings.

FillLibraryDataStructure(std::vector); // is the API of this library. Any app can call this API & pass a vector of string to this library. Example app code:

for(int i=100; i

Источник: https://stackoverflow.com/questions/448 ... data-struc
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»