945,066 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 6073
  • VB.NET RSS
May 2nd, 2006
0

Round-Robin Scheduling using threads, having some trouble

Expand Post »
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:

VB.NET Syntax (Toggle Plain Text)
  1. Imports System.Threading.Thread
  2.  
  3. Public Class ProcessClass
  4. Private _id As Integer
  5. Private _arrivalTime As Integer
  6. Private _ttl As Double
  7. Private _turnaround As Double
  8.  
  9. ' process ID
  10. Public ReadOnly Property ID() As Integer
  11. Get
  12. Return _id
  13. End Get
  14. End Property
  15.  
  16. ' This is the time in seconds at which the process is to arrive in the ready list
  17. Public ReadOnly Property ArrivalTime() As Integer
  18. Get
  19. Return _arrivalTime
  20. End Get
  21. End Property
  22.  
  23. ' this is the amount of execution time (in seconds) that the process needs to complete
  24. Public ReadOnly Property TTL() As Double
  25. Get
  26. Return _ttl
  27. End Get
  28. End Property
  29.  
  30. ' this is the amount of time elapsed from when it's first loaded to when it's completely done
  31. Public ReadOnly Property Turnaround() As Double
  32. Get
  33. Return _turnaround
  34. End Get
  35. End Property
  36.  
  37. Public Sub New(ByVal ID As Integer, ByVal ArrivalTime As Integer, ByVal TTL As Single)
  38. _id = ID
  39. _arrivalTime = ArrivalTime
  40. _ttl = TTL
  41. End Sub
  42.  
  43. ' simulates execution of the process by decrementing the TTL by the given quantum (in milliseconds) of execution
  44. Public Sub Update(ByVal Quantum As Integer)
  45. If _ttl * 1000 < Quantum Then
  46. Sleep(_ttl * 1000)
  47. _turnaround += Quantum / 1000
  48. _ttl = 0
  49.  
  50. Else
  51. Sleep(Quantum)
  52. _turnaround += Quantum / 1000
  53. _ttl -= Quantum / 1000
  54.  
  55. End If
  56. End Sub
  57. End Class

and this is the code for my actual round-robin scheduler program:
VB.NET Syntax (Toggle Plain Text)
  1. Imports System.IO
  2. Imports System.Threading.Thread
  3.  
  4. Module RRSimulation
  5.  
  6. Dim ReadyListThread As Threading.Thread
  7. Dim SchedulerThread As Threading.Thread
  8.  
  9. ' dispatcher overhead (in milliseconds)
  10. Dim Overhead As Integer
  11.  
  12. ' processing time (in milliseconds)
  13. Dim Quantum As Integer
  14.  
  15. ' holds the full processlist from the text file
  16. Dim ProcessList As Generic.Queue(Of ProcessClass)
  17.  
  18. ' the actual readylist, loaded from the processlist
  19. Dim ReadyList As Generic.Queue(Of ProcessClass)
  20.  
  21. ' simulate processes arriving into the readylist
  22. Public Sub ProcessArrives()
  23. ' check for more arriving processes
  24. While ProcessList.Count > 0
  25.  
  26. ' add new process to ready list
  27. Dim proc As ProcessClass = ProcessList.Dequeue
  28. ReadyList.Enqueue(proc)
  29.  
  30. ' show confirmation
  31. Console.WriteLine("Process {0} arrives at {1} with execution time {2}", proc.ID, Now.ToLongTimeString, proc.TTL)
  32.  
  33. ' wait for next process to be ready
  34. If ProcessList.Peek IsNot Nothing Then Sleep((ProcessList.Peek.ArrivalTime - proc.ArrivalTime) * 1000)
  35. End While
  36. End Sub
  37.  
  38. Public Sub ScheduleReadyProcess()
  39. While ReadyList.Count > 0
  40. ' get the next process
  41. Dim proc As ProcessClass = ReadyList.Dequeue()
  42. Console.WriteLine(" Executing Process {0} for {1} milliseconds. Current TTL: {2}", proc.ID, Quantum, proc.TTL)
  43.  
  44. ' run process
  45. proc.Update(Quantum)
  46. Console.WriteLine(" Done executing Process {0}. New TTL: {1}", proc.ID, proc.TTL)
  47.  
  48. ' if not finished, requeue
  49. If proc.TTL > 0 Then ProcessList.Enqueue(proc)
  50. End While
  51. End Sub
  52.  
  53.  
  54. Sub Main()
  55.  
  56. ' Initialize
  57. Overhead = 5
  58. Quantum = 50
  59. ProcessList = New Generic.Queue(Of ProcessClass)
  60. ReadyList = New Generic.Queue(Of ProcessClass)
  61.  
  62. ' Load the process list file
  63. Dim counter As Integer = 0
  64. Dim fReader As New StreamReader(Environment.CurrentDirectory & "\times.txt")
  65. While Not fReader.EndOfStream
  66. counter += 1
  67. Dim delim() As Char = {" ", vbTab}
  68. Dim cols() As String = fReader.ReadLine.Split(delim, StringSplitOptions.RemoveEmptyEntries)
  69. ProcessList.Enqueue(New ProcessClass(counter, CInt(cols(0)), CType(cols(1), Single)))
  70. End While
  71.  
  72. ' begin queuing up processes
  73. ReadyListThread = New Threading.Thread(AddressOf ProcessArrives)
  74. ReadyListThread.Start()
  75.  
  76. ' begin scheduling processes
  77. SchedulerThread = New Threading.Thread(AddressOf ScheduleReadyProcess)
  78. SchedulerThread.Start()
  79.  
  80. End Sub
  81.  
  82. End Module

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

-SelArom
Similar Threads
Reputation Points: 20
Solved Threads: 1
Junior Poster in Training
SelArom is offline Offline
54 posts
since Oct 2004
May 2nd, 2006
0

Re: Round-Robin Scheduling using threads, having some trouble

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
Reputation Points: 20
Solved Threads: 1
Junior Poster in Training
SelArom is offline Offline
54 posts
since Oct 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: currency rounding difficulties
Next Thread in VB.NET Forum Timeline: Help with VB.NET PLEASE.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC