/
glrbbir
/
ShedulerOS
Обзор
Документация
Войти
/
glrbbir
/
ShedulerOS
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
algorithms/rr.js
41 строка
898 B
Gleb
project
12 июн 2026, 19:15
12 июн 2026, 19:15
9180c5a
Код
Авторство
О чём код?
/** * RR (Round Robin) * Циклически выполняет каждый поток квантами времени. */ class RRScheduler extends Scheduler { constructor(params = {}) { super('RR', params); this.quantum = params.quantum || 10; } schedule(threads) { this._rrQueue = []; this._enqueued = new Set(); this._preempted = null; return super.schedule(threads); } _getTimeSlice(thread) { return Math.min(thread.remainingTime, this.quantum); } _pickNextThread(ready) { for (const t of ready) { if (!this._enqueued.has(t.id)) { this._rrQueue.push(t); this._enqueued.add(t.id); } } if (this._preempted !== null) { this._rrQueue.push(this._preempted); this._preempted = null; } return this._rrQueue.shift(); } _onThreadPreempted(thread) { this._preempted = thread; } }