O'Reilly logo

Getting Started with the Internet of Things by Cuno Pfister

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Multithreading

Buffer

An instance of class Buffer provides a threadsafe way of communication between actors (see Chapter 13). A buffer instance basically acts as a variable whose current value can be read and written:

public sealed class Buffer
{
    public void HandlePut(object o);
    public object HandleGet();
}
  • void HandlePut(object o)

    This method puts o into the buffer. The new value in the buffer replaces the old one. At most one value is buffered; there is no queuing of multiple values. The method performs the necessary locking to enable safe use of the buffer from multiple threads. Object o may be null.

  • void HandleGet()

    This method gets the current buffer state, without changing it. The method performs the necessary locking to enable safe use of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required