void Producer(int bufSize, int itemCnt, int randSeed) { srand(randSeed); // Write code here to produce itemCnt integer values in the range [0-100] // Use the functions provided below to get/set the values of shared variables "in" and "out" // Use the provided function WriteAtBufIndex() to write into the bounded buffer // Use the provided function GetRand() to generate a random number in the specified range // **Extremely Important: Remember to set the value of any shared variable you change locally // Use the following print statement to report the production of an item: // printf("Producing Item %d with value %d at Index %d\n", i, val, in); // where i is the item number, val is the item value, in is its index in the bounded buffer int i; for(i=0;i < GetItemCnt(); i++){ while(((GetIn()+1) % GetBufSize())==GetOut()) ; int rando = GetRand(0,100); WriteAtBufIndex(GetIn(),rando); printf("Producing Item %d with value %d at Index %d\n", i+1, rando, GetIn()); SetIn((GetIn()+1) % GetBufSize()); } printf("Producer Completed\n"); }
bool charshell::Handle() { if(!SetWrite()) { return false; } *ostr<<"Begin time: "; WriteTime(); if(!SetMode()) { return false; } if(!SetKey()) { return false; } if(!SetIn()) { return false; } if(!SetOut()) { return false; } if(!Setlog()) { return false; } if(mode == "3" && !SetReout()) { return false; } if(mode == "1") { filedes m_filedes(in, out, key, true); m_filedes.Inicialize(); m_filedes.Process(); } else if(mode == "2") { filedes m_filedes(in, out, key, false); m_filedes.Inicialize(); m_filedes.Process(); } else if(mode == "3") { filedes m_filedes(in, out, key, true); m_filedes.Inicialize(); m_filedes.Process(); out->close(); delete out; out = 0; ifstream iftmp(outPath.c_str(), ios::binary); filedes m_filedes2(&iftmp, reout, key, false); m_filedes2.Inicialize(); m_filedes2.Process(); } *ostr<<"End time: "; WriteTime(); string tmp = ostr->str(); cout<<tmp; *log<<tmp; return false; }
ProcessSamples::ProcessSamples(IMFSample *sample): in(NULL), out(NULL) { SetIn(sample); }