<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to WorkingWithThreads</title><link>https://sourceforge.net/p/madara/wiki/WorkingWithThreads/</link><description>Recent changes to WorkingWithThreads</description><atom:link href="https://sourceforge.net/p/madara/wiki/WorkingWithThreads/feed" rel="self"/><language>en</language><lastBuildDate>Fri, 04 May 2018 17:19:47 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/madara/wiki/WorkingWithThreads/feed" rel="self" type="application/rss+xml"/><item><title>WorkingWithThreads modified by James Edmondson</title><link>https://sourceforge.net/p/madara/wiki/WorkingWithThreads/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v21
+++ v22
@@ -1,5 +1,5 @@
 &lt;b&gt;C++ Guide Series&lt;/b&gt;
-[Architecture](MadaraArchitecture) | [Knowledge Base](InteractingWithTheKnowledgeBase) | [Networking](InteractingWithTheTransport) | [Containers](KnowledgeContainers) | Threads | [Optimizations](OptimizingKaRL) | [KaRL](KarlLanguage) | [Encryption](Encryption)
+[Architecture](MadaraArchitecture) | [Knowledge Base](InteractingWithTheKnowledgeBase) | [Networking](InteractingWithTheTransport) | [Containers](KnowledgeContainers) | Threads | [Optimizations](OptimizingKaRL) | [KaRL](KarlLanguage) | [Encryption](Encryption) | [Checkpointing](Checkpointing)

 ----

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">James Edmondson</dc:creator><pubDate>Fri, 04 May 2018 17:19:47 -0000</pubDate><guid>https://sourceforge.net15d740dfbe550e750a660c4bbeb5fac3304a0c4d</guid></item><item><title>WorkingWithThreads modified by James Edmondson</title><link>https://sourceforge.net/p/madara/wiki/WorkingWithThreads/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v20
+++ v21
@@ -1,5 +1,5 @@
 &lt;b&gt;C++ Guide Series&lt;/b&gt;
-[Architecture](MadaraArchitecture) | [Knowledge Base](InteractingWithTheKnowledgeBase) | [Networking](InteractingWithTheTransport) | [Containers](KnowledgeContainers) | Threads | [Optimizations](OptimizingKaRL) | [KaRL](KarlLanguage)
+[Architecture](MadaraArchitecture) | [Knowledge Base](InteractingWithTheKnowledgeBase) | [Networking](InteractingWithTheTransport) | [Containers](KnowledgeContainers) | Threads | [Optimizations](OptimizingKaRL) | [KaRL](KarlLanguage) | [Encryption](Encryption)

 ----

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">James Edmondson</dc:creator><pubDate>Sat, 21 Apr 2018 01:14:37 -0000</pubDate><guid>https://sourceforge.netb403e09124877c86c23b575aba5608caa2fbf8ee</guid></item><item><title>WorkingWithThreads modified by James Edmondson</title><link>https://sourceforge.net/p/madara/wiki/WorkingWithThreads/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v19
+++ v20
@@ -2,8 +2,6 @@
 [Architecture](MadaraArchitecture) | [Knowledge Base](InteractingWithTheKnowledgeBase) | [Networking](InteractingWithTheTransport) | [Containers](KnowledgeContainers) | Threads | [Optimizations](OptimizingKaRL) | [KaRL](KarlLanguage)

 ----
-
-**NOTE: MADARA has changed naming conventions for C++ in version 2.9.1. Wiki Documentation is still being updated for the new namespaces and class naming conventions.**

 # MADARA Threads

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">James Edmondson</dc:creator><pubDate>Thu, 16 Mar 2017 23:40:09 -0000</pubDate><guid>https://sourceforge.netf59bee071a862454ef265ef48a86fa9f7cb1b1b5</guid></item><item><title>WorkingWithThreads modified by James Edmondson</title><link>https://sourceforge.net/p/madara/wiki/WorkingWithThreads/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v18
+++ v19
@@ -1,5 +1,5 @@
 &lt;b&gt;C++ Guide Series&lt;/b&gt;
-[Architecture](MadaraArchitecture) | [Knowledge Base](InteractingWithTheKnowledgeBase) | [Networking](InteractingWithTheTransport) | [Containers](KnowledgeContainers) | Threads | [Optimizations](OptimizingKaRL)
+[Architecture](MadaraArchitecture) | [Knowledge Base](InteractingWithTheKnowledgeBase) | [Networking](InteractingWithTheTransport) | [Containers](KnowledgeContainers) | Threads | [Optimizations](OptimizingKaRL) | [KaRL](KarlLanguage)

 ----

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">James Edmondson</dc:creator><pubDate>Sun, 07 Feb 2016 20:29:33 -0000</pubDate><guid>https://sourceforge.netfcbd8df3ebd2867665e993225b6fb1899aa92470</guid></item><item><title>WorkingWithThreads modified by James Edmondson</title><link>https://sourceforge.net/p/madara/wiki/WorkingWithThreads/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v17
+++ v18
@@ -382,9 +382,9 @@

 # 5. Understanding the Threader wait function

-[Threader::wait](file:///C:/Users/jedmondson/Code/MADARA/docs/karl/html/d8/de5/classmadara_1_1threads_1_1Threader.html#a74548504f5ca748c34dd1c24e541d8f0) is a useful function that can be used to wait for the termination of one thread or all threads. However, it can also be used as a multifunctional sleep statement that either waits for thread termination or a time has passed, whichever happens first.
-
-As of 2.9.14, there are two versions of Threader::wait. The [first version](file:///C:/Users/jedmondson/Code/MADARA/docs/karl/html/d8/de5/classmadara_1_1threads_1_1Threader.html#a74548504f5ca748c34dd1c24e541d8f0) waits for all threads to complete or the timeout indicated in [WaitSettings](file:///C:/Users/jedmondson/Code/MADARA/docs/karl/html/d5/dec/structmadara_1_1knowledge_1_1WaitSettings.html) has occurred. The [second version](file:///C:/Users/jedmondson/Code/MADARA/docs/karl/html/d8/de5/classmadara_1_1threads_1_1Threader.html#a8298d9f05def330b888a6c17394db567) is a targeted wait statement that waits for a specific thread to terminate or a timeout has occurred. The return value for these functions will indicate whether or not the particular threads being waited on have terminated. If false is returned, then the timeout occurred.
+[Threader::wait](http://madara.sourceforge.net/docs/cpp/d8/de5/classmadara_1_1threads_1_1Threader.html#a8298d9f05def330b888a6c17394db567) is a useful function that can be used to wait for the termination of one thread or all threads. However, it can also be used as a multifunctional sleep statement that either waits for thread termination or a time has passed, whichever happens first.
+
+As of 2.9.14, there are two versions of Threader::wait. The [first version](http://madara.sourceforge.net/docs/cpp/d8/de5/classmadara_1_1threads_1_1Threader.html#a74548504f5ca748c34dd1c24e541d8f0) waits for all threads to complete or the timeout indicated in [WaitSettings](http://madara.sourceforge.net/docs/cpp/d5/dec/structmadara_1_1knowledge_1_1WaitSettings.html) has occurred. The [second version](http://madara.sourceforge.net/docs/cpp/d8/de5/classmadara_1_1threads_1_1Threader.html#a8298d9f05def330b888a6c17394db567) is a targeted wait statement that waits for a specific thread to terminate or a timeout has occurred. The return value for these functions will indicate whether or not the particular threads being waited on have terminated. If false is returned, then the timeout occurred.

 ----

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">James Edmondson</dc:creator><pubDate>Fri, 18 Dec 2015 01:25:07 -0000</pubDate><guid>https://sourceforge.net9d765a20c24483506d5cb13cd661ba711fc05e73</guid></item><item><title>WorkingWithThreads modified by James Edmondson</title><link>https://sourceforge.net/p/madara/wiki/WorkingWithThreads/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v16
+++ v17
@@ -380,7 +380,15 @@

 ----

-# 5. Using Thread-Safe Queues
+# 5. Understanding the Threader wait function
+
+[Threader::wait](file:///C:/Users/jedmondson/Code/MADARA/docs/karl/html/d8/de5/classmadara_1_1threads_1_1Threader.html#a74548504f5ca748c34dd1c24e541d8f0) is a useful function that can be used to wait for the termination of one thread or all threads. However, it can also be used as a multifunctional sleep statement that either waits for thread termination or a time has passed, whichever happens first.
+
+As of 2.9.14, there are two versions of Threader::wait. The [first version](file:///C:/Users/jedmondson/Code/MADARA/docs/karl/html/d8/de5/classmadara_1_1threads_1_1Threader.html#a74548504f5ca748c34dd1c24e541d8f0) waits for all threads to complete or the timeout indicated in [WaitSettings](file:///C:/Users/jedmondson/Code/MADARA/docs/karl/html/d5/dec/structmadara_1_1knowledge_1_1WaitSettings.html) has occurred. The [second version](file:///C:/Users/jedmondson/Code/MADARA/docs/karl/html/d8/de5/classmadara_1_1threads_1_1Threader.html#a8298d9f05def330b888a6c17394db567) is a targeted wait statement that waits for a specific thread to terminate or a timeout has occurred. The return value for these functions will indicate whether or not the particular threads being waited on have terminated. If false is returned, then the timeout occurred.
+
+----
+
+# 6. Using Thread-Safe Queues

 A common paradigm to use for parallel programming is to create a queue between threads, the most frequent of which is generally a solution to the producer/consumer problem. The central idea to the producer/consumer concept is that a producer creates information for the consumers to consume and utilize. A queue encapsulates this interaction intuitively, and in this section, we'll cover how to setup your own producer/consumer application quickly and easily with MADARA.

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">James Edmondson</dc:creator><pubDate>Fri, 18 Dec 2015 01:19:23 -0000</pubDate><guid>https://sourceforge.net78e4c56f0c1accaad9f6c000271d9a6b460a039f</guid></item><item><title>WorkingWithThreads modified by James Edmondson</title><link>https://sourceforge.net/p/madara/wiki/WorkingWithThreads/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v15
+++ v16
@@ -7,7 +7,7 @@

 # MADARA Threads

-As of 1.9.12, MADARA supports fast, portable user-threads that interact with each other over data and control planes. With the addition of the [Threader](http://madara.sourceforge.net/docs/cpp/db/d90/classMadara_1_1Threads_1_1Threader.html) class and the extensible [Base_Thread](http://madara.sourceforge.net/docs/cpp/db/d03/classMadara_1_1Threads_1_1Base__Thread.html), users can now make intuitive applications that not only perform distributed collaboration and communication but can also take advantage of multiple cores on a local node to really speed up computation and performance.
+As of 1.9.12, MADARA supports fast, portable user-threads that interact with each other over data and control planes. With the addition of the [Threader](http://madara.sourceforge.net/docs/cpp/d8/de5/classmadara_1_1threads_1_1Threader.html) class and the extensible [BaseThread](http://madara.sourceforge.net/docs/cpp/de/dcd/classmadara_1_1threads_1_1BaseThread.html), users can now make intuitive applications that not only perform distributed collaboration and communication but can also take advantage of multiple cores on a local node to really speed up computation and performance.

 ----

@@ -542,7 +542,7 @@

 You may have noticed that the jobs queue created in the above example uses a local variable prefix (".jobs") to keep the queue local. This is important and it's also a powerful concept to learn about the Queue container.

-Why is this important? [Queue](http://madara.sourceforge.net/docs/cpp/d9/dd9/classmadara_1_1knowledge_1_1containers_1_1Queue.html) is thread-safe but not necessarily process-safe. If you have multiple consumers/producers across nodes in your network, the timing of producing and consuming is likely to produce race conditions due to the way consistency is enforced within the MADARA engine.
+Why is this important? [Queue](http://madara.sourceforge.net/docs/cpp/d8/dd1/classmadara_1_1knowledge_1_1containers_1_1Queue.html) is thread-safe but not necessarily process-safe. If you have multiple consumers/producers across nodes in your network, the timing of producing and consuming is likely to produce race conditions due to the way consistency is enforced within the MADARA engine.

 For instance, node1 may have a producer thread and node2 may have a producer thread. If both of them enqueue a job at the same time, each will place a task on the queue simultaneously. Whoever writes last to this index in the queue will end up having its item in the queue, and due to network latency, it is very possible that a queue between nodes would have inconsistent production/consumption ordering. In many cases, this may be fine, but for most applications this is likely to be a debugging nightmare.

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">James Edmondson</dc:creator><pubDate>Mon, 19 Oct 2015 01:51:14 -0000</pubDate><guid>https://sourceforge.netfbe7d371ca02aeb8ad2a890aec36ff9675e88f62</guid></item><item><title>WorkingWithThreads modified by James Edmondson</title><link>https://sourceforge.net/p/madara/wiki/WorkingWithThreads/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v14
+++ v15
@@ -3,6 +3,8 @@

 ----

+**NOTE: MADARA has changed naming conventions for C++ in version 2.9.1. Wiki Documentation is still being updated for the new namespaces and class naming conventions.**
+
 # MADARA Threads

 As of 1.9.12, MADARA supports fast, portable user-threads that interact with each other over data and control planes. With the addition of the [Threader](http://madara.sourceforge.net/docs/cpp/db/d90/classMadara_1_1Threads_1_1Threader.html) class and the extensible [Base_Thread](http://madara.sourceforge.net/docs/cpp/db/d03/classMadara_1_1Threads_1_1Base__Thread.html), users can now make intuitive applications that not only perform distributed collaboration and communication but can also take advantage of multiple cores on a local node to really speed up computation and performance.
@@ -17,7 +19,7 @@

 To use the `Threader` class, you need to do the following things:

-1. Extend a `Base_Thread` and implement the run method
+1. Extend a `BaseThread` and implement the run method
 * Create a Knowledge Base
 * Create a Threader
 * Run threads
@@ -29,15 +31,15 @@

 ~~~~~~
 #include &amp;lt;iostream&amp;gt;
-#include "madara/knowledge_engine/Knowledge_Base.h"
+#include "madara/knowledge/KnowledgeBase.h"
 #include "madara/threads/Threader.h"

 // some shortcuts for common MADARA namespaces
-namespace engine = Madara::Knowledge_Engine;
-namespace threads = Madara::Threads;
+namespace engine = madara::knowledge;
+namespace threads = madara::threads;

 // 1: Extend a Base_Thread
-class Hello_World : public threads::Base_Thread
+class HelloWorld : public threads::BaseThread
 {
   public:
     void run (void)
@@ -49,13 +51,13 @@
 int main (int argc, char ** argv)
 {
   // 2: Create a Knowledge Base
-  engine::Knowledge_Base knowledge;
+  engine::KnowledgeBase knowledge;

   // 3: Create a Threader 
   threads::Threader threader (knowledge);

   // 4: Run threads
-  threader.run ("hello_world", new Hello_World ());
+  threader.run ("hello_world", new HelloWorld ());

   // 5: Wait for threads to finish
   threader.wait ();
@@ -68,11 +70,11 @@

 ----

-# 2. Understanding `Base_Thread`
-
-`Madara::Threads::Base_Thread` is a simple class with some really powerful features. We only showed part of what's possible with the Hello World example. Next, we'll show how you can make your threads work together to accomplish a simple task, but first, we need to go over the features of the `Base_Thread` and exactly what you're inheriting.
-
-`Base_Thread` has three total virtual functions, but two of them have default implementations, so you don't have to implement them unless you want to. The run method is the only method that is required, and that's what we used in Hello World to print the message to the screen.
+# 2. Understanding `BaseThread`
+
+`madara::threads::BaseThread` is a simple class with some really powerful features. We only showed part of what's possible with the Hello World example. Next, we'll show how you can make your threads work together to accomplish a simple task, but first, we need to go over the features of the `BaseThread` and exactly what you're inheriting.
+
+`BaseThread` has three total virtual functions, but two of them have default implementations, so you don't have to implement them unless you want to. The run method is the only method that is required, and that's what we used in Hello World to print the message to the screen.

 The other two methods are `init` and `cleanup`, and their signatures are outlined in the following code segment (taken from the Base_Thread header file):

@@ -81,7 +83,7 @@
  * Initializes thread with MADARA context
  * @param   context   context for querying current program state
  **/
- virtual void init (Knowledge_Engine::Knowledge_Base &amp;amp; context)
+ virtual void init (madara::knowledge::KnowledgeBase &amp;amp; context)
  {
  }

@@ -109,17 +111,17 @@

 ~~~~~~
 #include &amp;lt;iostream&amp;gt;
-#include "madara/knowledge_engine/Knowledge_Base.h"
+#include "madara/knowledge/KnowledgeBase.h"
 #include "madara/threads/Threader.h"
 #include "madara/utility/Utility.h"

 // some shortcuts for common MADARA namespaces
-namespace engine = Madara::Knowledge_Engine;
-namespace threads = Madara::Threads;
-namespace utility = Madara::Utility;
+namespace engine = madara::knowledge;
+namespace threads = madara::threads;
+namespace utility = madara::utility;

 // A nagging thread that just keeps saying hello until terminated
-class Nagging_Hello_World : public threads::Base_Thread
+class NaggingHelloWorld : public threads::BaseThread
 {
   public:
     void run (void)
@@ -134,10 +136,10 @@
 // the main function
 int main (int argc, char ** argv)
 {
-  engine::Knowledge_Base knowledge;
+  engine::KnowledgeBase knowledge;

   threads::Threader threader(knowledge);
-  threader.run ("hello_world", new Nagging_Hello_World ());
+  threader.run ("hello_world", new NaggingHelloWorld ());

   // sleep for 10 seconds so the thread can nag at us
   utility::sleep (10.0);
@@ -162,21 +164,21 @@

 ~~~~~~
 #include &amp;lt;sstream&amp;gt;
-#include "madara/knowledge_engine/Knowledge_Base.h"
+#include "madara/knowledge/KnowledgeBase.h"
 #include "madara/threads/Threader.h"
 #include "madara/utility/Utility.h"

 // some shortcuts for common MADARA namespaces
-namespace engine = Madara::Knowledge_Engine;
-namespace threads = Madara::Threads;
-namespace utility = Madara::Utility;
-namespace containers = engine::Containers;
+namespace engine = madara::knowledge;
+namespace threads = madara::threads;
+namespace utility = madara::utility;
+namespace containers = engine::containers;

 // A nagging thread that says hello until terminated
-class Nagging_Hello_World : public threads::Base_Thread
+class NaggingHelloWorld : public threads::BaseThread
 {
   public:
-    void init (engine::Knowledge_Base &amp;amp; data)
+    void init (engine::KnowledgeBase &amp;amp; data)
     {
       knowledge = data;
     }
@@ -200,15 +202,15 @@
       knowledge.print ("Nagging thread is shutting down.\n");
     }

-    engine::Knowledge_Base knowledge;
+    engine::KnowledgeBase knowledge;
 };

 // a counter thread that works with other counters
-class Counter_Thread : public threads::Base_Thread
+class CounterThread : public threads::BaseThread
 {
 public:

-  void init (engine::Knowledge_Base &amp;amp; context)
+  void init (engine::KnowledgeBase &amp;amp; context)
   {
     // reference a counter variable in the context
     counter.set_name ("counter", context);
@@ -240,22 +242,22 @@

 private:
   containers::Integer counter;
-  engine::Knowledge_Base data;
+  engine::KnowledgeBase data;
 };

 // the main function
 int main (int argc, char ** argv)
 {
-  engine::Knowledge_Base knowledge;
+  engine::KnowledgeBase knowledge;

   threads::Threader threader (knowledge);

   // run a nagger thread
-  threader.run ("nagger", new Nagging_Hello_World ());
+  threader.run ("nagger", new NaggingHelloWorld ());

   // run the two counter threads
-  threader.run ("counter1", new Counter_Thread ());
-  threader.run ("counter2", new Counter_Thread ());
+  threader.run ("counter1", new CounterThread ());
+  threader.run ("counter2", new CounterThread ());

   // sleep for 3 seconds so the thread can nag us for a bit
   utility::sleep (3.0);
@@ -287,7 +289,7 @@

 An alternative method for controlling threads is to allow periodic execution of each thread. We cover periodic thread execution in the following example.

-Instead of having two uncontrolled counters, we will instead create two controlled counters operating at 20hz (20 executions per second) and 40hz each. Creating extensions of the `Base_Thread` for this type of controlled threading paradigm usually simplifies threading significantly, as the Threader class and associated worker threads will check the paused and terminated flags for you, in between executions. However, as you will see in the example, you can set the terminated flags yourself if it's appropriate.
+Instead of having two uncontrolled counters, we will instead create two controlled counters operating at 20hz (20 executions per second) and 40hz each. Creating extensions of the `BaseThread` for this type of controlled threading paradigm usually simplifies threading significantly, as the Threader class and associated worker threads will check the paused and terminated flags for you, in between executions. However, as you will see in the example, you can set the terminated flags yourself if it's appropriate.

 There are two main development changes required for using periodic threads rather than bursty threads. First, we need to implement a run method that does not continuously loop, but instead only does some useful bit of work one time. Second, we need to call the `Threader::run` method that takes in a hertz parameter for controlling the thread execution.

@@ -298,22 +300,22 @@

 ~~~~~~
 #include &amp;lt;sstream&amp;gt;
-#include "madara/knowledge_engine/Knowledge_Base.h"
+#include "madara/knowledge/KnowledgeBase.h"
 #include "madara/threads/Threader.h"
 #include "madara/utility/Utility.h"

 // some shortcuts for common MADARA namespaces
-namespace engine = Madara::Knowledge_Engine;
-namespace threads = Madara::Threads;
-namespace utility = Madara::Utility;
-namespace containers = engine::Containers;
+namespace engine = madara::knowledge;
+namespace threads = madara::threads;
+namespace utility = madara::utility;
+namespace containers = engine::containers;

 // a counter thread that works with other counters
-class Counter_Thread : public threads::Base_Thread
+class CounterThread : public threads::BaseThread
 {
 public:

-  void init (engine::Knowledge_Base &amp;amp; context)
+  void init (engine::KnowledgeBase &amp;amp; context)
   {
     // reference a counter variable in the context
     counter.set_name ("counter", context);
@@ -352,7 +354,7 @@
   containers::Integer counter;

   /// the knowledge base that contains the counter and allows printing
-  engine::Knowledge_Base data;
+  engine::KnowledgeBase data;

   /// the message we want to print
   std::string message;
@@ -361,13 +363,13 @@
 // the main function
 int main (int, char **)
 {
-  engine::Knowledge_Base knowledge;
+  engine::KnowledgeBase knowledge;

   threads::Threader threader (knowledge);

   // run the two counter threads, one at 20hz and one at 40hz
-  threader.run (20.0, "counter1", new Counter_Thread ());
-  threader.run (40.0, "counter2", new Counter_Thread ());
+  threader.run (20.0, "counter1", new CounterThread ());
+  threader.run (40.0, "counter2", new CounterThread ());

   // the other threads self terminate when they reach 1000
   threader.wait ();
@@ -389,28 +391,28 @@
 ~~~~~~
 #include &amp;lt;iostream&amp;gt;

-#include "madara/knowledge_engine/Knowledge_Base.h"
+#include "madara/knowledge/KnowledgeBase.h"
 #include "madara/threads/Threader.h"
 #include "madara/utility/Utility.h"
-#include "madara/knowledge_engine/containers/Queue.h"
+#include "madara/knowledge/containers/Queue.h"

 // some shortcuts for common MADARA namespaces
-namespace engine = Madara::Knowledge_Engine;
-namespace threads = Madara::Threads;
-namespace utility = Madara::Utility;
-namespace containers = engine::Containers;
+namespace engine = madara::knowledge;
+namespace threads = madara::threads;
+namespace utility = madara::utility;
+namespace containers = engine::containers;

 /**
  * A consumer of action types
  **/
-class Consumer: public threads::Base_Thread
+class Consumer: public threads::BaseThread
 {
 public:
   /**
     * Initializes thread with MADARA context
     * @param   context   context for querying current program state
     **/
-  virtual void init (engine::Knowledge_Base &amp;amp; context)
+  virtual void init (engine::KnowledgeBase &amp;amp; context)
   {
     // initialize references to variables in the knowledge base
     jobs.set_name (".jobs", context);
@@ -425,7 +427,7 @@
   virtual void run (void)
   {
     // dequeue until terminated
-    Madara::Knowledge_Record job jobs.dequeue (false);
+    engine::KnowledgeRecord job jobs.dequeue (false);

     if (job.is_valid ())
     {
@@ -462,20 +464,20 @@
 private:
   containers::Queue jobs;
   containers::Integer jobs_completed;
-  engine::Knowledge_Base data;
+  engine::KnowledgeBase data;
 };

 /**
  * A producer of action types for consumers to perform
  **/
-class Producer: public threads::Base_Thread
+class Producer: public threads::BaseThread
 {
 public:
   /**
     * Initializes thread with MADARA context
     * @param   context   context for querying current program state
     **/
-  virtual void init (engine::Knowledge_Base &amp;amp; context)
+  virtual void init (engine::KnowledgeBase &amp;amp; context)
   {
     // create a reference to the jobs queue
     jobs.set_name (".jobs", context);
@@ -495,19 +497,19 @@
     /**
       * generate job consisting of 4 possible events: (int: 0-3)
       **/
-    jobs.enqueue (Madara::Utility::rand_int (0, 3, false));
+    jobs.enqueue (madara::utility::rand_int (0, 3, false));
   }

 private:
   containers::Queue jobs;
-  engine::Knowledge_Base data;
+  engine::KnowledgeBase data;
 };

 // the main function
 int main (int, char **)
 {
-  engine::Knowledge_Base knowledge;
+  engine::KnowledgeBase knowledge;

   threads::Threader threader (knowledge);

@@ -540,7 +542,7 @@

 You may have noticed that the jobs queue created in the above example uses a local variable prefix (".jobs") to keep the queue local. This is important and it's also a powerful concept to learn about the Queue container.

-Why is this important? [Queue](http://madara.sourceforge.net/docs/cpp/d9/dd9/classMadara_1_1Knowledge__Engine_1_1Containers_1_1Queue.html) is thread-safe but not necessarily process-safe. If you have multiple consumers/producers across nodes in your network, the timing of producing and consuming is likely to produce race conditions due to the way consistency is enforced within the MADARA engine.
+Why is this important? [Queue](http://madara.sourceforge.net/docs/cpp/d9/dd9/classmadara_1_1knowledge_1_1containers_1_1Queue.html) is thread-safe but not necessarily process-safe. If you have multiple consumers/producers across nodes in your network, the timing of producing and consuming is likely to produce race conditions due to the way consistency is enforced within the MADARA engine.

 For instance, node1 may have a producer thread and node2 may have a producer thread. If both of them enqueue a job at the same time, each will place a task on the queue simultaneously. Whoever writes last to this index in the queue will end up having its item in the queue, and due to network latency, it is very possible that a queue between nodes would have inconsistent production/consumption ordering. In many cases, this may be fine, but for most applications this is likely to be a debugging nightmare.

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">James Edmondson</dc:creator><pubDate>Sat, 10 Oct 2015 03:57:15 -0000</pubDate><guid>https://sourceforge.net58fb5fd938ab421c883447a3c9cac717c7964040</guid></item><item><title>WorkingWithThreads modified by James Edmondson</title><link>https://sourceforge.net/p/madara/wiki/WorkingWithThreads/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v13
+++ v14
@@ -33,8 +33,8 @@
 #include "madara/threads/Threader.h"

 // some shortcuts for common MADARA namespaces
-namespace engine Madara::Knowledge_Engine;
-namespace threads Madara::Threads;
+namespace engine = Madara::Knowledge_Engine;
+namespace threads = Madara::Threads;

 // 1: Extend a Base_Thread
 class Hello_World : public threads::Base_Thread
@@ -114,9 +114,9 @@
 #include "madara/utility/Utility.h"

 // some shortcuts for common MADARA namespaces
-namespace engine Madara::Knowledge_Engine;
-namespace threads Madara::Threads;
-namespace utility Madara::Utility;
+namespace engine = Madara::Knowledge_Engine;
+namespace threads = Madara::Threads;
+namespace utility = Madara::Utility;

 // A nagging thread that just keeps saying hello until terminated
 class Nagging_Hello_World : public threads::Base_Thread
@@ -167,10 +167,10 @@
 #include "madara/utility/Utility.h"

 // some shortcuts for common MADARA namespaces
-namespace engine Madara::Knowledge_Engine;
-namespace threads Madara::Threads;
-namespace utility Madara::Utility;
-namespace containers engine::Containers;
+namespace engine = Madara::Knowledge_Engine;
+namespace threads = Madara::Threads;
+namespace utility = Madara::Utility;
+namespace containers = engine::Containers;

 // A nagging thread that says hello until terminated
 class Nagging_Hello_World : public threads::Base_Thread
@@ -303,10 +303,10 @@
 #include "madara/utility/Utility.h"

 // some shortcuts for common MADARA namespaces
-namespace engine Madara::Knowledge_Engine;
-namespace threads Madara::Threads;
-namespace utility Madara::Utility;
-namespace containers engine::Containers;
+namespace engine = Madara::Knowledge_Engine;
+namespace threads = Madara::Threads;
+namespace utility = Madara::Utility;
+namespace containers = engine::Containers;

 // a counter thread that works with other counters
 class Counter_Thread : public threads::Base_Thread
@@ -395,10 +395,10 @@
 #include "madara/knowledge_engine/containers/Queue.h"

 // some shortcuts for common MADARA namespaces
-namespace engine Madara::Knowledge_Engine;
-namespace threads Madara::Threads;
-namespace utility Madara::Utility;
-namespace containers engine::Containers;
+namespace engine = Madara::Knowledge_Engine;
+namespace threads = Madara::Threads;
+namespace utility = Madara::Utility;
+namespace containers = engine::Containers;

 /**
  * A consumer of action types
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">James Edmondson</dc:creator><pubDate>Sun, 09 Nov 2014 03:53:50 -0000</pubDate><guid>https://sourceforge.net4c871ff407d4703e91c7b2ead0d11279a01813a4</guid></item><item><title>WorkingWithThreads modified by James Edmondson</title><link>https://sourceforge.net/p/madara/wiki/WorkingWithThreads/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v12
+++ v13
@@ -477,6 +477,7 @@
     **/
   virtual void init (engine::Knowledge_Base &amp;amp; context)
   {
+    // create a reference to the jobs queue
     jobs.set_name (".jobs", context);

     data context;
@@ -510,6 +511,10 @@

   threads::Threader threader (knowledge);

+  // create the initial jobs queue
+  containers::Queue jobs (".jobs", knowledge);
+  jobs.resize (100);
+
   /**
    * explicitly set random seed to right now for randomizer engine.
    * Subsequent calls to MADARA random funcs should use false for 3rd arg
@@ -542,8 +547,8 @@
 Each node can have multiple producers and consumers acting independently of other producers and consumers on other nodes because it is using a local job queue between threads on the node. This is the recommended way to use the thread-safe Queue container. *The only recommended way to use a Queue container for distributed applications (i.e., not only multithreaded but multiprocessed) is to create a queue between each producer and consumer (a direct channel between them), so that each queue is representing a 1:1 relationship between producer and consumer.* That should work fine.

 In conclusion, a couple of points to keep in mind about the Queue container.
-  # It is very useful for multithreaded applications
-  # It is rarely useful for distributed applications. Be careful with how you use Queue in distributed applications.
+ * It is very useful for multithreaded applications
+ * It is rarely useful for distributed applications. Be careful with how you use Queue in distributed applications.

 ----

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">James Edmondson</dc:creator><pubDate>Wed, 05 Nov 2014 07:36:32 -0000</pubDate><guid>https://sourceforge.net98da15bd4f6e400789dafae49d369472617c709f</guid></item></channel></rss>