Commit Graph

7 Commits

Author SHA1 Message Date
Avi Kivity
edcd346d83 thread: fix thread-created-within-thread
The thread switching code assumed that we will always switch out of a
thread due to being blocked on an unavailable future.  This allows
the core to store the blocked thread's context in the synthetic
continuation chained to that future (which switched back to that thread).

That assumption failed in one place: when we create a thread from within a
thread.  In that case we switch to the new thread immediately, but forget
all about the old thread.  We never come back to the old thread, and anything
that depends on it hangs.

Fix by creating a linked list of active thread contexts.  These are all
threads that have been "preempted" by the act of creating a new thread,
terminated by the main, unthreaded, reactor context.  This gives us a place
to store those threads and we come back to them and continue where we left
off.

Reported by Pekka.
2015-06-16 17:04:02 +03:00
Avi Kivity
5251c2523a thread: point out async() as an easy way to launch a thread 2015-06-14 09:14:30 +03:00
Avi Kivity
980a7dc881 thread: more documentation 2015-06-14 08:56:42 +03:00
Avi Kivity
3986ad6a11 thread: add seastar::async()
Following std::async(), seastar::async(func) causes func to be executed
in a seastar thread, where it can block using future<>::get().  Whatever
func returns is converted to a future, and returned as async()s return
value.
2015-06-04 20:57:00 +03:00
Asias He
88e7dcfa86 Remove redundant const in static constexpr const
From http://en.cppreference.com/w/cpp/language/constexpr:

   A constexpr specifier used in an object declaration implies const.

However, We can not change from
   static constexpr const char* TIME_FORMAT = "%a %b %d %I:%M:%S %Z %Y";
to
   static constexpr char* TIME_FORMAT = "%a %b %d %I:%M:%S %Z %Y";

The compiler complains:

   In file included from json/formatter.cc:22:0:
   json/formatter.hh:132:42: error: deprecated conversion from string
   constant to ‘char*’ [-Werror=write-strings]
        static constexpr char* TIME_FORMAT = "%a %b %d %I:%M:%S %Z %Y";

Since, unlike const, constexpr does not modify a type. It just applies
to an object (or function), and incidentally implies const to the
top-level type.
2015-05-25 11:57:19 +03:00
Avi Kivity
784e03aa31 thread: use setjmp/longjmp for context switches
swapcontext() is expensive as it invokes system calls.  Replace it with
setjmp()/longjmp().  We still use setcontext() initially, since that's
the most reasonable portable method of setting up a stack.

Context switch time (measured by thread_context_switch) is reduced to
120ns (from 450ns), with inefficiencies in the test itself and in future<>
dominating.
2015-05-17 17:22:48 +03:00
Avi Kivity
cd0ae463b3 core: thread support
Add a thread class that can be used to launch a blockable thread of
execution.  Within a thread, future<>::get() can be called on an
unavailable future, in which case it blocks until the future is made ready.
2015-05-17 15:57:11 +03:00