hi! I haven't been here in a while, but i'm glad you're still around since I need some help! I've got to implement a round-robin simulation of process execution. I've decided to do this in VB.NET because it's my strongest language and it's a difficult concept! I've got some of the stuff working but I'm kind of stuck and I think it might be my understanding of threading in .net rather than my understanding of the round robin scheduling.

the way the project works is I have a text file with two column lines. the first column represents the time at which the process arrives in the ready list. the second column is how long the process needs to be in execution to finish.

so far I've set up two threads: one to feed the ready list, and one to execute the processes in the ready list. if I run them individually they work pretty awesome! but when I try to run them together, I get problems. namely, the second thread (that simulates execution) will run once, then it waits for the first thread to finish before executing again. it seems as if the first thread is somehow blocking the second but I didn't think that was possible since they are seperate threads!!

okay well it might be more clear what I'm saying if I show you my code. here is the class for the simulated process:

Imports System.Threading.Thread

Public Class ProcessClass
    Private _id As Integer
    Private _arrivalTime As Integer
    Private _ttl As Double
    Private _turnaround As Double

    ' process ID
    Public ReadOnly Property ID() As Integer
        Get
            Return _id
        End Get
    End Property

    ' This is the time in seconds at which the process is to arrive in the ready list
    Public ReadOnly Property ArrivalTime() As Integer
        Get
            Return _arrivalTime
        End Get
    End Property

    ' this is the amount of execution time (in seconds) that the process needs to complete
    Public ReadOnly Property TTL() As Double
        Get
            Return _ttl
        End Get
    End Property

    ' this is the amount of time elapsed from when it's first loaded to when it's completely done
    Public ReadOnly Property Turnaround() As Double
        Get
            Return _turnaround
        End Get
    End Property

    Public Sub New(ByVal ID As Integer, ByVal ArrivalTime As Integer, ByVal TTL As Single)
        _id = ID
        _arrivalTime = ArrivalTime
        _ttl = TTL
    End Sub

    ' simulates execution of the process by decrementing the TTL by the given quantum (in milliseconds) of execution
    Public Sub Update(ByVal Quantum As Integer)
        If _ttl * 1000 < Quantum Then
            Sleep(_ttl * 1000)
            _turnaround += Quantum / 1000
            _ttl = 0

        Else
            Sleep(Quantum)
            _turnaround += Quantum / 1000
            _ttl -= Quantum / 1000

        End If
    End Sub
End Class

and this is the code for my actual round-robin scheduler program:

Imports System.IO
Imports System.Threading.Thread

Module RRSimulation

    Dim ReadyListThread As Threading.Thread
    Dim SchedulerThread As Threading.Thread

    ' dispatcher overhead (in milliseconds)
    Dim Overhead As Integer

    ' processing time (in milliseconds)
    Dim Quantum As Integer

    ' holds the full processlist from the text file
    Dim ProcessList As Generic.Queue(Of ProcessClass)

    ' the actual readylist, loaded from the processlist
    Dim ReadyList As Generic.Queue(Of ProcessClass)

    ' simulate processes arriving into the readylist
    Public Sub ProcessArrives()
        ' check for more arriving processes
        While ProcessList.Count > 0

            ' add new process to ready list
            Dim proc As ProcessClass = ProcessList.Dequeue
            ReadyList.Enqueue(proc)

            ' show confirmation
            Console.WriteLine("Process {0} arrives at {1} with execution time {2}", proc.ID, Now.ToLongTimeString, proc.TTL)

            ' wait for next process to be ready
            If ProcessList.Peek IsNot Nothing Then Sleep((ProcessList.Peek.ArrivalTime - proc.ArrivalTime) * 1000)
        End While
    End Sub

    Public Sub ScheduleReadyProcess()
        While ReadyList.Count > 0
            ' get the next process
            Dim proc As ProcessClass = ReadyList.Dequeue()
            Console.WriteLine("    Executing Process {0} for {1} milliseconds. Current TTL: {2}", proc.ID, Quantum, proc.TTL)

            ' run process
            proc.Update(Quantum)
            Console.WriteLine("    Done executing Process {0}. New TTL: {1}", proc.ID, proc.TTL)

            ' if not finished, requeue
            If proc.TTL > 0 Then ProcessList.Enqueue(proc)
        End While
    End Sub


    Sub Main()

        ' Initialize
        Overhead = 5
        Quantum = 50
        ProcessList = New Generic.Queue(Of ProcessClass)
        ReadyList = New Generic.Queue(Of ProcessClass)

        ' Load the process list file
        Dim counter As Integer = 0
        Dim fReader As New StreamReader(Environment.CurrentDirectory & "\times.txt")
        While Not fReader.EndOfStream
            counter += 1
            Dim delim() As Char = {" ", vbTab}
            Dim cols() As String = fReader.ReadLine.Split(delim, StringSplitOptions.RemoveEmptyEntries)
            ProcessList.Enqueue(New ProcessClass(counter, CInt(cols(0)), CType(cols(1), Single)))
        End While

        ' begin queuing up processes
        ReadyListThread = New Threading.Thread(AddressOf ProcessArrives)
        ReadyListThread.Start()

        ' begin scheduling processes
        SchedulerThread = New Threading.Thread(AddressOf ScheduleReadyProcess)
        SchedulerThread.Start()

    End Sub

End Module

can anyone see what i'm doing wrong? I really appreciate it!

-SelArom

never mind i found the problem! I was reenqueueing the executing process into the processlist, when I should have been reenqueueing into the ready list!! duh. thanks!

-SelArom

I'd like to use your codes using visual studio 2010, it's not running because I don't know your design. please help me :(

This question has already been answered. Start a new discussion instead.