<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.vbex.ru/index.php?action=history&amp;feed=atom&amp;title=VB.Net%2FThread%2FBuffer</id>
		<title>VB.Net/Thread/Buffer - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.vbex.ru/index.php?action=history&amp;feed=atom&amp;title=VB.Net%2FThread%2FBuffer"/>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net/Thread/Buffer&amp;action=history"/>
		<updated>2026-04-05T15:53:46Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.vbex.ru/index.php?title=VB.Net/Thread/Buffer&amp;diff=904&amp;oldid=prev</id>
		<title> в 16:40, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net/Thread/Buffer&amp;diff=904&amp;oldid=prev"/>
				<updated>2010-05-26T16:40:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 16:40, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.vbex.ru/index.php?title=VB.Net/Thread/Buffer&amp;diff=905&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net/Thread/Buffer&amp;diff=905&amp;oldid=prev"/>
				<updated>2010-05-26T12:45:29Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Circular Buffer Demo==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;vbnet&amp;quot;&amp;gt;&lt;br /&gt;
Imports System&lt;br /&gt;
Imports System.Threading&lt;br /&gt;
Public Class MainClass&lt;br /&gt;
   Shared Sub Main()&lt;br /&gt;
      &amp;quot; create shared object&lt;br /&gt;
      Dim sharedLocation As New CHoldIntegerSynchronized()&lt;br /&gt;
      sharedLocation.CreateStateOutput()&lt;br /&gt;
      &amp;quot; Random object used by each thread&lt;br /&gt;
      Dim randomObject As New Random()&lt;br /&gt;
      &amp;quot; create CProducer and CConsumer objects&lt;br /&gt;
      Dim producer As New CProducer(sharedLocation, randomObject)&lt;br /&gt;
      Dim consumer As New CConsumer(sharedLocation, randomObject)&lt;br /&gt;
      &amp;quot; create threads&lt;br /&gt;
      Dim producerThread As New Thread(AddressOf producer.Produce)&lt;br /&gt;
      Dim consumerThread As New Thread(AddressOf consumer.Consume)&lt;br /&gt;
      &amp;quot; name threads&lt;br /&gt;
      producerThread.Name = &amp;quot;Producer&amp;quot;&lt;br /&gt;
      consumerThread.Name = &amp;quot;Consumer&amp;quot;&lt;br /&gt;
      &amp;quot; start threads&lt;br /&gt;
      producerThread.Start()&lt;br /&gt;
      consumerThread.Start()&lt;br /&gt;
   End Sub &amp;quot; Main&lt;br /&gt;
End Class&lt;br /&gt;
Public Class CConsumer&lt;br /&gt;
   Private sharedLocation As CHoldIntegerSynchronized&lt;br /&gt;
   Private randomSleepTime As Random&lt;br /&gt;
   &amp;quot; constructor&lt;br /&gt;
   Public Sub New(ByVal sharedObject As CHoldIntegerSynchronized, _&lt;br /&gt;
      ByVal randomObject As Random)&lt;br /&gt;
      sharedLocation = sharedObject&lt;br /&gt;
      randomSleepTime = randomObject&lt;br /&gt;
   End Sub&lt;br /&gt;
   Public Sub Consume()&lt;br /&gt;
      Dim count, sum As Integer&lt;br /&gt;
      For count = 1 To 10&lt;br /&gt;
         Thread.Sleep(randomSleepTime.Next(1, 3000))&lt;br /&gt;
         sum += sharedLocation.Buffer&lt;br /&gt;
      Next&lt;br /&gt;
      Console.WriteLine( &amp;quot;Total &amp;quot; &amp;amp; _&lt;br /&gt;
         Thread.CurrentThread.Name &amp;amp; &amp;quot; consumed: &amp;quot; &amp;amp; sum &amp;amp; vbCrLf &amp;amp; _&lt;br /&gt;
         Thread.CurrentThread.Name &amp;amp; &amp;quot; terminated.&amp;quot; )&lt;br /&gt;
   End Sub&lt;br /&gt;
End Class&lt;br /&gt;
Public Class CHoldIntegerSynchronized&lt;br /&gt;
   Private mBuffer As Integer() = {-1, -1, -1}&lt;br /&gt;
   Private occupiedBufferCount As Integer&lt;br /&gt;
   Private readlocation, writeLocation As Integer&lt;br /&gt;
   Public Sub New()&lt;br /&gt;
   End Sub &amp;quot; New&lt;br /&gt;
   Property Buffer() As Integer&lt;br /&gt;
      Get&lt;br /&gt;
         SyncLock (Me)&lt;br /&gt;
            If occupiedBufferCount = 0 Then&lt;br /&gt;
               Console.WriteLine( &amp;quot;All buffers empty. &amp;quot; &amp;amp; _&lt;br /&gt;
                  Thread.CurrentThread.Name &amp;amp; &amp;quot; waits.&amp;quot; )&lt;br /&gt;
               Monitor.Wait(Me)&lt;br /&gt;
            End If&lt;br /&gt;
            Dim readValue As Integer = mBuffer(readlocation)&lt;br /&gt;
            Console.WriteLine( Thread.CurrentThread.Name &amp;amp; &amp;quot; reads &amp;quot; &amp;amp; _&lt;br /&gt;
               mBuffer(readlocation) )&lt;br /&gt;
            occupiedBufferCount -= 1&lt;br /&gt;
            readlocation = (readlocation + 1) Mod mBuffer.Length&lt;br /&gt;
            CreateStateOutput() &lt;br /&gt;
            Monitor.Pulse(Me)&lt;br /&gt;
            Return readValue&lt;br /&gt;
         End SyncLock&lt;br /&gt;
      End Get&lt;br /&gt;
      Set(ByVal Value As Integer)&lt;br /&gt;
         SyncLock (Me)&lt;br /&gt;
            If occupiedBufferCount = mBuffer.Length Then&lt;br /&gt;
               Console.WriteLine( &amp;quot;All buffers full. &amp;quot; &amp;amp; _&lt;br /&gt;
                  Thread.CurrentThread.Name &amp;amp; &amp;quot; waits.&amp;quot; )&lt;br /&gt;
               Monitor.Wait(Me)&lt;br /&gt;
            End If&lt;br /&gt;
            mBuffer(writeLocation) = Value&lt;br /&gt;
            Console.WriteLine( Thread.CurrentThread.Name &amp;amp; &amp;quot; writes &amp;quot; &amp;amp; _&lt;br /&gt;
               mBuffer(writeLocation) )&lt;br /&gt;
            occupiedBufferCount += 1&lt;br /&gt;
            writeLocation = (writeLocation + 1) Mod _&lt;br /&gt;
               mBuffer.Length&lt;br /&gt;
            CreateStateOutput() &lt;br /&gt;
            Monitor.Pulse(Me)&lt;br /&gt;
         End SyncLock&lt;br /&gt;
      End Set&lt;br /&gt;
   End Property &amp;quot; Buffer&lt;br /&gt;
   Public Sub CreateStateOutput()&lt;br /&gt;
      Dim i As Integer&lt;br /&gt;
      Console.WriteLine( &amp;quot;(buffers occupied: &amp;quot; &amp;amp; _&lt;br /&gt;
         occupiedBufferCount &amp;amp; &amp;quot;)&amp;quot; &amp;amp; vbCrLf &amp;amp; &amp;quot;buffers: &amp;quot; )&lt;br /&gt;
      For i = 0 To mBuffer.GetUpperBound(0)&lt;br /&gt;
         Console.Write( &amp;quot; &amp;quot; &amp;amp; mBuffer(i) &amp;amp; &amp;quot;  &amp;quot; )&lt;br /&gt;
      Next&lt;br /&gt;
      For i = 0 To mBuffer.GetUpperBound(0)&lt;br /&gt;
         Console.Write( &amp;quot;---- &amp;quot; )&lt;br /&gt;
      Next&lt;br /&gt;
&lt;br /&gt;
      For i = 0 To mBuffer.GetUpperBound(0)&lt;br /&gt;
         If (i = writeLocation AndAlso _&lt;br /&gt;
            writeLocation = readlocation) Then&lt;br /&gt;
            Console.Write( &amp;quot; WR  &amp;quot; )&lt;br /&gt;
         ElseIf i = writeLocation Then&lt;br /&gt;
            Console.Write( &amp;quot; W   &amp;quot; )&lt;br /&gt;
         ElseIf i = readlocation Then&lt;br /&gt;
            Console.Write( &amp;quot;  R  &amp;quot; )&lt;br /&gt;
         Else&lt;br /&gt;
            Console.Write( &amp;quot;     &amp;quot; )&lt;br /&gt;
         End If&lt;br /&gt;
      Next&lt;br /&gt;
   End Sub&lt;br /&gt;
End Class&lt;br /&gt;
Public Class CProducer&lt;br /&gt;
   Private sharedLocation As CHoldIntegerSynchronized&lt;br /&gt;
   Private randomSleepTime As Random&lt;br /&gt;
   Public Sub New(ByVal sharedObject As CHoldIntegerSynchronized, _&lt;br /&gt;
      ByVal randomObject As Random)&lt;br /&gt;
      sharedLocation = sharedObject&lt;br /&gt;
      randomSleepTime = randomObject&lt;br /&gt;
   End Sub &amp;quot; New&lt;br /&gt;
   Public Sub Produce()&lt;br /&gt;
      Dim count As Integer&lt;br /&gt;
      For count = 11 To 20&lt;br /&gt;
         Thread.Sleep(randomSleepTime.Next(1, 3000))&lt;br /&gt;
         sharedLocation.Buffer = count&lt;br /&gt;
      Next&lt;br /&gt;
      Console.WriteLine( Thread.CurrentThread.Name &amp;amp; _&lt;br /&gt;
         &amp;quot; done producing. &amp;quot; &amp;amp; vbCrLf &amp;amp; _&lt;br /&gt;
         Thread.CurrentThread.Name &amp;amp; &amp;quot; terminated.&amp;quot; )&lt;br /&gt;
   End Sub&lt;br /&gt;
End Class&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>