Hello Tim,
A producer-Consumer solution using queues should solve your problem. I have attached below a starter for what I am refering to. There are two producer loops, each of wich will enqueue the data and a tag for the data. The data and tag are clusterred so that you can check the tag whenever you dequeue the data.
In the consumer loop, you can check the tag every time that you dequeue an element and act according to the tag. You can even dequeue directly to file and save both the data and the tag, that way when you read the file, you can check the tag and act accordingly.
Hope it helps.