x=0;
t=0;

 int t2=0,t3;
 while(t<=ref)
  {t3=t2;

   for(x=0;x<jbn;x++)
	{ if(t==cpy2[x].at)
	    {
	       if(q>=cpy2[x].bt)
		      {
		      t2+=cpy2[x].bt;
		      tt[x++]=t2;
		      cpy2[x].bt=0;
		      qq++;
		      }
	       else if(q<cpy2[x].bt)
		       {
		       t2+=q;
		       cpy2[x].bt-=q;
		       cpy2[x].at=t2;
		       qq++;
		       }
	     }
	    else
	    break;
	    }


   t++;
   if(t3==t2)
	{t2++;}
   };

assuming the values are
cpy2[0].at==1
cpy2[0].bt==2
cpy2[1].at==2
cpy2[1].bt==3
cpy2[2].at==4
cpy2[2].bt==4
q==2
qq is just an add on
jbn==3
and
ref==10

the results are tt[]={3,5,9}

but we want tt[]={3,8,10}

can you help?

p.s.
dont suggest to initialize tt[] by that.... we need process!!

Dani AI

Generated

This is a classic round‑robin scheduling bug, not an “urgent” mystery — the symptoms point to index corruption and in‑place mutation of arrival data rather than a math error. The code posted by updates the loop index (and then writes into the array using that updated index) while iterating the same array and also reuses arrival times to represent re‑queuing. That combination will skip processes and write completion times to the wrong slots.

A robust fix is to stop scanning the whole array every tick and instead use a proper ready queue (FIFO). In plain steps:

  • Keep each process record with separate fields: arrival, remaining (not overwriting arrival), and completion.
  • Maintain current_time and a queue of process indexes.
  • When current_time advances, enqueue any processes whose arrival <= current_time.
  • Dequeue an index, run for min(quantum, remaining), advance current_time, subtract from remaining; if remaining==0 record completion, otherwise enqueue the index again.
  • If the queue is empty, jump current_time to the next arrival instead of busy‑looping.

A minimal C‑style outline (illustrative) follows:

// proc[i].at, proc[i].rem; completion[i] = -1 initially
int qhead=0, qtail=0, queue[N];
int time = 0, finished = 0;
enqueue newly arrived indexes whose at <= time;

while (finished < N) {
    if (qhead == qtail) { time = next_arrival_time(); enqueue that index; continue; }
    int id = queue[qhead++]; int run = min(quantum, proc[id].rem);
    proc[id].rem -= run; time += run;
    if (proc[id].rem == 0) { completion[id] = time; finished++; }
    else queue[qtail++] = id;
    enqueue any processes now arrived whose at <= time;
}

Do not increment the loop index inside the body, and avoid overwriting arrival timestamps to mean “next ready time.” For reference on the algorithm behavior and edge cases, see Round‑robin scheduling. As advised: post a minimal reproducible example if you want a line‑by‑line diagnosis; and per and , keep the thread self‑contained and avoid “urgent” in the title.

Recommended Answers

All 3 Replies

>can you help?
Yes.
This is what you need.

>>>can you help?
No -- I have no clue what that program is supposed to do. Don't expect me to read your other threads -- a thread should stand on its own.

And posts should NEVER be marked urgent! It's not urgent to us -- we'll get to it when we get to it. And many people simply bypass threads titled like this so you've just cut down your chances for help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.