public static WaitTimeGenerator GetInstance(ICDFFunction cDFFunction)
        {
            if (instance == null)
            {
                lock (padlock)
                {
                    if (instance == null)
                    {
                        instance = new WaitTimeGenerator(cDFFunction);
                    }
                }
            }

            return(instance);
        }
        private void BtnGenerateProcess_Click(object sender, EventArgs e)
        {
            int               noOfProcesses = Int32.Parse(txtNoOfProcess.Text);
            ICDFFunction      uniformDistributionFunction = new UniformDistributionFunction();
            WaitTimeGenerator waitTimeGenerator           = WaitTimeGenerator.GetInstance(uniformDistributionFunction);
            List <Process>    inputProcesses = waitTimeGenerator.GenerateProcesses(noOfProcesses);

            //cpu scheduling simulation
            SchedulingAlgorithm fcfsPreemptive = new FirstComeFirstServe(inputProcesses);
            Schedule            fcfsSchedule   = fcfsPreemptive.GenerateProcessSchedule();

            SchedulingAlgorithm priorityNonPreemptive = new PriorityNonPreemptive(inputProcesses);
            Schedule            pnpSchedule           = priorityNonPreemptive.GenerateProcessSchedule();

            SchedulingAlgorithm shortestRemainingJobFirst = new ShortestRemainingJobFirst(inputProcesses);
            Schedule            srjfSchedule = shortestRemainingJobFirst.GenerateProcessSchedule();

            List <object[]> listProcesses, listFCFSSchedule, listPNPSchedule, listSRJFSchedule;

            listProcesses    = new List <Object[]>();
            listFCFSSchedule = new List <Object[]>();
            listPNPSchedule  = new List <Object[]>();
            listSRJFSchedule = new List <Object[]>();
            List <string> strDataset = new List <string>();
            List <string> fcfsTurn   = new List <string>();
            List <string> pnpTurn    = new List <string>();
            List <string> srjfTurn   = new List <string>();

            string labels = "";

            int totalFCFSTurnAroundTime = 0, totalPNPTurnAroundTime = 0, totalSRJFTurnAroundTime = 0;

            foreach (Process process in inputProcesses)
            {
                string pid = process.GetProcessID();
                labels += String.Format("\"{0}\",", pid);
                listProcesses.Add(new object[] {
                    pid,
                    process.GetArrivalTime(),
                    process.GetBurstTime(),
                    process.GetIOBlockTime()
                });

                int fcfsTurnAroundTime = fcfsSchedule.GetTurnAroundTime(process);
                totalFCFSTurnAroundTime += fcfsTurnAroundTime;

                int endTime = fcfsSchedule.GetEndTime(process);

                fcfsTurn.Add(fcfsTurnAroundTime.ToString());
                listFCFSSchedule.Add(new object[] {
                    pid,
                    process.GetArrivalTime(),
                    endTime,
                    fcfsTurnAroundTime
                });

                int pnpTurnAroundTime = pnpSchedule.GetTurnAroundTime(process);
                totalPNPTurnAroundTime += pnpTurnAroundTime;

                endTime = pnpSchedule.GetEndTime(process);
                pnpTurn.Add(pnpTurnAroundTime.ToString());
                listPNPSchedule.Add(new object[] {
                    pid,
                    process.GetArrivalTime(),
                    endTime,
                    pnpSchedule.GetTurnAroundTime(process)
                });

                int srjfTurnAroundTime = srjfSchedule.GetTurnAroundTime(process);
                totalSRJFTurnAroundTime += srjfTurnAroundTime;

                endTime = srjfSchedule.GetEndTime(process);
                srjfTurn.Add(pnpTurnAroundTime.ToString());
                listSRJFSchedule.Add(new object[] {
                    pid,
                    process.GetArrivalTime(),
                    endTime,
                    srjfSchedule.GetTurnAroundTime(process)
                });
            }

            strDataset.Add(ConvertToJSON(new Dictionary <string, object>()
            {
                { "label", "First Come First Serve" },
                { "data", String.Join(",", fcfsTurn.ToArray()) }
            }));
            strDataset.Add(ConvertToJSON(new Dictionary <string, object>()
            {
                { "label", "Priority Non Preemptive" },
                { "data", String.Join(",", pnpTurn.ToArray()) }
            }));
            strDataset.Add(ConvertToJSON(new Dictionary <string, object>()
            {
                { "label", "Shortest Remaining Job First" },
                { "data", String.Join(",", srjfTurn.ToArray()) }
            }));
            labels = labels.Substring(0, labels.Length - 1);
            int avgFCFSSchedule, avgPNPSchedule, avgSRJFSchedule;

            avgFCFSSchedule = totalFCFSTurnAroundTime / noOfProcesses;
            avgPNPSchedule  = totalPNPTurnAroundTime / noOfProcesses;
            avgSRJFSchedule = totalSRJFTurnAroundTime / noOfProcesses;

            lblFCFSAvgTurnAround.Text = avgFCFSSchedule.ToString();
            lblPNPAvgTurnAround.Text  = avgPNPSchedule.ToString();
            lblSRJFAvgTurnAround.Text = avgSRJFSchedule.ToString();

            LoadDataGrid(grdProcesses, processBindingSource, ConvertListToDataTable(listProcesses));
            LoadDataGrid(grdFCFSSchedule, fcfsScheduleBindingSource, ConvertListToDataTable(listFCFSSchedule, false));
            LoadDataGrid(grdPNPSchedule, pnpScheduleBindingSource, ConvertListToDataTable(listPNPSchedule, false));
            LoadDataGrid(grdSRJFSchedule, srjfScheduleBindingSource, ConvertListToDataTable(listSRJFSchedule, false));

            GenerateGanttChart(strDataset.ToArray(), labels);
        }