Click here to Skip to main content
15,885,984 members
Home / Discussions / C#
   

C#

 
GeneralRe: s Text Property in a TreeNode Pin
Heath Stewart22-Apr-04 4:14
protectorHeath Stewart22-Apr-04 4:14 
GeneralRe: s Text Property in a TreeNode Pin
Bill Dean22-Apr-04 4:24
Bill Dean22-Apr-04 4:24 
GeneralRe: s Text Property in a TreeNode Pin
Heath Stewart22-Apr-04 4:30
protectorHeath Stewart22-Apr-04 4:30 
GeneralRe: s Text Property in a TreeNode Pin
Bill Dean22-Apr-04 4:41
Bill Dean22-Apr-04 4:41 
GeneralCircular Buffer Technique question Pin
TimTM22-Apr-04 3:45
TimTM22-Apr-04 3:45 
GeneralRe: Circular Buffer Technique question Pin
Jeremy Kimball22-Apr-04 5:48
Jeremy Kimball22-Apr-04 5:48 
GeneralRe: Circular Buffer Technique question Pin
TimTM22-Apr-04 8:10
TimTM22-Apr-04 8:10 
GeneralRe: Circular Buffer Technique question Pin
scadaguy22-Apr-04 6:26
scadaguy22-Apr-04 6:26 
Multithreaded programming is extremely difficult. Even those who are consider experts at it frequently make mistakes. The producer/consumer problem isn't trivial. It is most easily solved with semaphores[^].

public class Buffer
{

  private int in = 0;
  private int out = 0;
  private object[] buffer = new object[CAPACITY];
  private Semaphore full = new Semaphore(CAPACITY);
  private Semaphore empty = new Semaphore(0);
  private Semaphore mutex = new Semaphore(1);
  <br>
  public object Thing
  {
    get
    {
      mutex.WaitOne();
      empty.WaitOne();
      object t = buffer[out];
      out = (out + 1) % buffer.Length;
      full.AddOne();
      mutex.AddOne();
      return t;
    }
    set
    {
      full.WaitOne();
      mutex.WaitOne();
      object t = buffer[in];
      in = (in + 1) % buffer.Length;
      buffer[in] = value;
      mutex.AddOne();
      empty.AddOne();
    }
  }
}


Notice that this implementation isn't trivial. Furthermore, the Semaphore implementation isn't trivial either.
GeneralRe: Circular Buffer Technique question Pin
TimTM22-Apr-04 8:04
TimTM22-Apr-04 8:04 
GeneralRe: Circular Buffer Technique question Pin
scadaguy22-Apr-04 8:44
scadaguy22-Apr-04 8:44 
GeneralRe: Circular Buffer Technique question Pin
TimTM22-Apr-04 9:01
TimTM22-Apr-04 9:01 
GeneralWindows Forms DataGrid Pin
dcronje22-Apr-04 3:39
dcronje22-Apr-04 3:39 
GeneralRe: Windows Forms DataGrid Pin
Heath Stewart22-Apr-04 5:04
protectorHeath Stewart22-Apr-04 5:04 
GeneralRe: Windows Forms DataGrid Pin
Jeremy Kimball22-Apr-04 6:08
Jeremy Kimball22-Apr-04 6:08 
GeneralRe: Windows Forms DataGrid Pin
Heath Stewart22-Apr-04 7:24
protectorHeath Stewart22-Apr-04 7:24 
GeneralRe: Windows Forms DataGrid Pin
Jeremy Kimball22-Apr-04 7:59
Jeremy Kimball22-Apr-04 7:59 
Generalmdb Synchronize Pin
basdanny22-Apr-04 3:00
basdanny22-Apr-04 3:00 
GeneralVss 6.0c Pin
sreejith ss nair22-Apr-04 2:14
sreejith ss nair22-Apr-04 2:14 
GeneralRe: Vss 6.0c Pin
Heath Stewart22-Apr-04 2:53
protectorHeath Stewart22-Apr-04 2:53 
GeneralRemote Debugging Pin
MrEyes22-Apr-04 1:53
MrEyes22-Apr-04 1:53 
GeneralRe: Remote Debugging Pin
Heath Stewart22-Apr-04 2:55
protectorHeath Stewart22-Apr-04 2:55 
GeneralRe: Remote Debugging Pin
Tom Larsen22-Apr-04 4:41
Tom Larsen22-Apr-04 4:41 
GeneralEvent in visual C# Pin
Hemant Mane22-Apr-04 0:57
Hemant Mane22-Apr-04 0:57 
GeneralRe: Event in visual C# Pin
A.Wegierski22-Apr-04 1:22
A.Wegierski22-Apr-04 1:22 
GeneralRe: Event in visual C# Pin
Heath Stewart22-Apr-04 2:59
protectorHeath Stewart22-Apr-04 2:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.