Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55612 - sandbox/task/libs/task/examples
From: oliver.kowalke_at_[hidden]
Date: 2009-08-16 09:08:02


Author: olli
Date: 2009-08-16 09:08:01 EDT (Sun, 16 Aug 2009)
New Revision: 55612
URL: http://svn.boost.org/trac/boost/changeset/55612

Log:
- missing headers added

Added:
   sandbox/task/libs/task/examples/buffer.hpp (contents, props changed)
   sandbox/task/libs/task/examples/semaphore.hpp (contents, props changed)

Added: sandbox/task/libs/task/examples/buffer.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/buffer.hpp 2009-08-16 09:08:01 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,59 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TASK_EXAMPLES_BUFFER_H
+#define BOOST_TASK_EXAMPLES_BUFFER_H
+
+#include <cstdlib>
+#include <string>
+
+#include <boost/assert.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/optional.hpp>
+
+#include "boost/task.hpp"
+
+namespace tsk = boost::task;
+
+inline
+void send_ping(
+ int n,
+ tsk::unbounded_buffer< std::string > & buf_ping,
+ tsk::unbounded_buffer< std::string > & buf_pong)
+{
+ for ( int i = 0; i < n; ++i)
+ {
+ printf("task 1: buf_ping.put(%d-th ping)\n", i);
+ buf_ping.put(
+ boost::lexical_cast< std::string >( i) + "-th ping");
+ boost::optional< std::string > msg;
+ buf_pong.take( msg);
+ BOOST_ASSERT( msg);
+ printf("task 1: buf_pong.take(%s)\n", msg->c_str() );
+ }
+ printf("task 1: end\n");
+}
+
+inline
+void send_pong(
+ int n,
+ tsk::unbounded_buffer< std::string > & buf_ping,
+ tsk::unbounded_buffer< std::string > & buf_pong)
+{
+ for ( int i = 0; i < n; ++i)
+ {
+ printf("task 2: buf_pong.put(%d-th pong)\n", i);
+ buf_pong.put(
+ boost::lexical_cast< std::string >( i) + "-th pong");
+ boost::optional< std::string > msg;
+ buf_ping.take( msg);
+ BOOST_ASSERT( msg);
+ printf("task 2: buf_ping.take(%s)\n", msg->c_str() );
+ }
+ printf("task 2: end\n");
+}
+
+#endif // BOOST_TASK_EXAMPLES_BUFFER_H

Added: sandbox/task/libs/task/examples/semaphore.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/semaphore.hpp 2009-08-16 09:08:01 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,64 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TASK_EXAMPLES_SEMAPHORE_H
+#define BOOST_TASK_EXAMPLES_SEMAPHORE_H
+
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+
+#include <boost/bind.hpp>
+#include <boost/ref.hpp>
+
+#include "boost/task.hpp"
+
+namespace tsk = boost::task;
+
+inline
+void loop_fn( int n)
+{
+ for ( int i = 0; i < n; ++i)
+ {
+ printf("task 3: %d-th iteration\n", i);
+ boost::this_task::block();
+ }
+ printf("task 3: end\n");
+}
+
+inline
+void start_with_sem_a(
+ int n,
+ tsk::semaphore & sem_a,
+ tsk::semaphore & sem_b)
+{
+ for ( int i = 0; i < n; ++i)
+ {
+ printf("task 1: %d-th sema_a.post()\n", i);
+ sem_a.post();
+ printf("task 1: %d-th sema_b.wait()\n", i);
+ sem_b.wait();
+ }
+ printf("task 1: end\n");
+}
+
+inline
+void start_with_sem_b(
+ int n,
+ tsk::semaphore & sem_a,
+ tsk::semaphore & sem_b)
+{
+ for ( int i = 0; i < n; ++i)
+ {
+ printf("task 2: %d-th sema_b.post()\n", i);
+ sem_b.post();
+ printf("task 2: %d-th sema_a.wait()\n", i);
+ sem_a.wait();
+ }
+ printf("task 2: end\n");
+}
+
+#endif // BOOST_TASK_EXAMPLES_SEMAPHORE_H


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk