close
//https://skydrive.live.com/view.aspx?resid=F1B8FF18A2AEC5C5!1176&cid=f1b8ff18a2aec5c5&app=WordPdf
#include <cstdio>
#include <iostream>
#include <iterator>
#include <string>
#include <fstream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <future>
#include <set>
#include <map>
  
using namespace std ;
  
template<class T> 
class monitor{ 
private
    mutable T t; 
    mutable std::mutex m;
public
    monitor(T t_ ) : t{t_} { }
  
    template<typename F>
    auto operator()( F f ) const-> decltype(f(t))
    {  
        std::lock_guard<mutex> hold{m}; 
        return f(t);  
    }
};
  
int funcint(int i)
{
    return i * i ;
}
double funcdouble(int i)
{
    return i * 1.0101 ;
}
  
  
int main()
{
    monitor<int> m1(100) ;
    int i1 ;
    double d1 ;
    i1 = m1(funcint) ;
    d1 = m1(funcdouble);
    cout << "i1=" << i1 << ",d1=" << d1 << endl ;
}
 
arrow
arrow
    全站熱搜

    hedgezzz 發表在 痞客邦 留言(0) 人氣()