active-objects

Marshalling an active object with JAXB?

試著忘記壹切 提交于 2019-12-11 10:34:23
问题 I am trying to marshal a class which extends Thread to XML, the code is as follows: @XmlRootElement public class TransitionXML extends Thread { ArcXML[] preArcs; ArcXML[] postArcs; int[] preArcTokens; int[] postArcTokens; int leastTime; int longestTime; String name; //some methods //a lot of get-set @Override public void run() { while (true) { if (this.postTransition() & this.preTransition()) { //We take out the tokens. this.executePreTranstion(); this.checkPreTransition(); try { this.sleep

Return values for active objects

吃可爱长大的小学妹 提交于 2019-11-30 06:41:31
问题 Back in 2010, Herb Sutter advocated the use of active objects instead of naked threads in an article on Dr. Dobb's. Here is a C++11 version: class Active { public: typedef std::function<void()> Message; Active(const Active&) = delete; void operator=(const Active&) = delete; Active() : done(false) { thd = std::unique_ptr<std::thread>(new std::thread( [=]{ this->run(); } ) ); } ~Active() { send( [&]{ done = true; } ); thd->join(); } void send(Message m) { mq.push_back(m); } private: bool done;