The gpc::qumex<
and class
DataType>gpc::qumex<
classes
as well as the class
KeyType, class
DataType>gpc::fork<
function constitute Generic Parallel Computing (GPC) API.
See also Reduction/MapReduce.
class
Function>
template<class void
|
Submit the function to the thread pool. A thread from the pool will call the function. Submitted functions are ordered FIFO. |
template<class void
|
Submit the function to the queue of mutual exclusion. A thread from the thread pool will call the function. At any moment of time only one thread can process a queue of mutual exclusion, but at different times different threads can process the same queue. Submitted functions are ordered FIFO. |
template<class void
|
Submit the function to the queue of mutual exclusion identified by the key. A thread from the thread pool will call the function. At any moment of time only one thread can process a queue of mutual exclusion, but at different times different threads can process the same queue. Submitted functions are ordered FIFO. |
gpc::mutex< gpc::mutex<
|
Arguments of the join callback functions. |
... // an HTTP entry void SomeHttpHandler::Process(tef::RequestContext& http) const { gpc::qumex<Foo*> qmx; while( /* condition */ ) { // do parallel database queries // while an HTTP context is referenced, the response is not sent. gpc::fork([http, qmx]() { try { struct Record { tef::db::type<__int64> uid; tef::db::type<wchar_t, 30> usr; ... }; tef::Db<Record> db(L"ms"); db << L"select UID, USR from ROOT where ..."; db >> db->uid >> db->usr ... ; Foo* data; while( db.Fetch() ) { // prepare some data } // merge the results and respond when it is done qmx.join([http, data](gpc::mutex<Foo*>& state) mutable { // exclusive access to the state, so let's merge and set ... state.setData(data); data.count++; // exclusive access to the HTTP context also if( data.count == /* condition */ ) { http.Output << state.getData(); http.Output.End(200); } } } catch(std::exception& e) { qmx.join([http, e](gpc::mutex<Foo*>& state) mutable { // exclusive access to the HTTP context http.Output << e.what(); http.Output.End(500); // it sends the response when there are no references to the HTTP context. } } }); } }
// in the global scope gpc::qumex<int, Foo*> gQmx; // an HTTP entry void SomeHttpHandler::Process(tef::RequestContext& http) const { int someId = http.Input["someId"]; gQmx.join(someId, [http](gpc::mutex<Foo*, int>& state) mutable { // exclusive access to the state identified by the someId ... // then http.Output << 123; // it sends the response (200) automatically when there are no references to the HTTP context. } }