public static int pick_cpu(int[] cpunum, int[] cycles, double end) //shadow note cpunum and cycles are reference so pass a table
    {
    	int cpu = last_activecpu;
    
    	/* look for a CPU that isn't suspended and hasn't run its full timeslice yet */
    	do
    	{
    		/* wrap around */
    		cpu += 1;
    		if (cpu > lastcpu)
    			cpu=0;//cpu = cpudata;
    
    		/* if this CPU is suspended, just bump its time */
    		if (cpudata[cpu].suspended!=0)
    		{
    			/* ASG 990225 - defer this update until the slice has finished */
    /*			if (!cpu->nocount)
    			{
    				cpu->time = end;
    				cpu->lost = 0;
    			}*/
    		}
    
    		/* if this CPU isn't suspended and has time left.... */
    		else if (cpudata[cpu].time < end)
    		{
    			/* mark the CPU active, and remember the CPU number locally */
    			activecpu = last_activecpu = cpu;
    
    			/* return the number of cycles to execute and the CPU number */
    			cpunum[0] = cpudata[cpu].index;
    			cycles[0] = (int)((double)(end - cpudata[cpu].time) * cpudata[cpu].sec_to_cycles);
    
    			if (cycles[0] > 0)
    			{

                            if(errorlog!=null) fprintf(errorlog,"T=%.6g: CPU %d runs %d cycles\n", cpudata[cpu].time + global_offset, cpunum[0], cycles[0]);

    				/* remember the base time for this CPU */
    				base_time = cpudata[cpu].time + ((double)cycles[0] * cpudata[cpu].cycles_to_sec);
    
    				/* success */
    				return 1;
    			}
    		}
    	}
    	while (cpu != last_activecpu);
    
    	/* ASG 990225 - bump all suspended CPU times after the slice has finished */
    	for (cpu=0; cpu<=lastcpu; cpu++)//for (cpu = cpudata; cpu <= lastcpu; cpu++)
    		if ((cpudata[cpu].suspended!=0) && (cpudata[cpu].nocount==0))
    		{
    			cpudata[cpu].time = end;
    			cpudata[cpu].lost = 0;
    		}
    
    	/* failure */
    	return 0;
    }