Пример #1
0
/* Determines the visibility for each cell in map.
 * Assumes an UINT1 points map and a spatial REAL8 dem map present. If a
 * cell has a MV in one of the maps, it gets a MV in the output map also.
 * Returns 0 if termination is successful, non-zero otherwise 
 */
int View(
     MAP_UINT1 *out,			/* write-only output map  */ 
     const MAP_REAL8 *dem, 		/* Dig. Elevation map	*/
     const MAP_UINT1 *points) 		/* points map	*/
{
     	UINT1 	pointVal;		/* value in points.map */
     	REAL8 	demVal;			/* value in dem map */
     	int 	r, c , nrRows, nrCols, v = 0;

     	nrRows = dem->NrRows(dem);
     	nrCols = dem->NrCols(dem);

	PRECOND(nrRows == points->NrRows(points));
	PRECOND(nrCols == points->NrCols(points));

	/* Fill out with FALSE, this is the initial value */
	for(r = 0; r < nrRows; r++)
	 for(c = 0; c < nrCols; c++)
	 {
		out->Put((UINT1)0, r, c, out);
	 }

	/* algorithm wants dem->Get() to return FALSE in case of MV */
	dem->SetGetTest(GET_MV_TEST, dem);
	points->SetGetTest(GET_MV_TEST, points);
	out->SetGetTest(GET_MV_TEST, out);

	/* For every view point in the points map */
	AppProgress("\nBusy with viewpoint:\n");
	for (r = 0; r < nrRows; r++)
	 for (c = 0; c < nrCols; c++)
	{
		if(dem->Get(&demVal, r, c, dem)&&
		(points->Get(&pointVal, r, c, points))&&
		(pointVal))
	   	{
	   		v++;
	   		AppProgress("\r%d          ", v);
			if(First(out, r, c, dem, points))
				return 1;
			if(Second(out, r, c, dem, points, nrCols))
				return 1;
			if(Third(out, r, c, dem, points, nrRows))
				return 1;
			if(Fourth(out, r, c, dem, points, nrRows,
								nrCols))
				return 1;
		}
	}
	AppEndRowProgress();
	return 0;		/* successful terminated */ 
}
Пример #2
0
int main(int argc, char **argv) {
    ctpl::thread_pool p(2 /* two threads in the pool */);

    std::future<void> qw = p.push(std::ref(first));  // function
    p.push(first);  // function
    p.push(aga, 7);  // function

    {
        struct Second {
            Second(const std::string & s) { std::cout << "Second ctor\n"; this->s = s; }
            Second(Second && c) { std::cout << "Second move ctor\n"; s = std::move(c.s); }
            Second(const Second & c) { std::cout << "Second copy ctor\n"; this->s = c.s; };
            ~Second() { std::cout << "Second dtor\n"; }
            void operator()(int id) const {
                std::cout << "hello from " << id << ' ' << this->s << '\n';
            }
        private:
            std::string s;
        } second(", functor");

        p.push(std::ref(second));  // functor, reference
        std::this_thread::sleep_for(std::chrono::milliseconds(2000));
        p.push(const_cast<const Second &>(second));  // functor, copy ctor
        p.push(std::move(second));  // functor, move ctor
        p.push(second);  // functor, move ctor
        p.push(Second(", functor"));  // functor, move ctor
    }
        {
            Third t(100);

            p.push(ugu, std::ref(t));  // function. reference
            p.push(ugu, t);  // function. copy ctor, move ctor
            p.push(ugu, std::move(t));  // function. move ctor, move ctor

        }
        p.push(ugu, Third(200));  // function



    std::string s = ", lambda";
    p.push([s](int id){  // lambda
        std::this_thread::sleep_for(std::chrono::milliseconds(2000));
        std::cout << "hello from " << id << ' ' << s << '\n';
    });

    p.push([s](int id){  // lambda
        std::this_thread::sleep_for(std::chrono::milliseconds(2000));
        std::cout << "hello from " << id << ' ' << s << '\n';
    });

    p.push(mmm, "worked");

    auto f = p.pop();
    if (f) {
        std::cout << "poped function from the pool ";
        f(0);
    }
    // change the number of treads in the pool

    p.resize(1);

    std::string s2 = "result";
    auto f1 = p.push([s2](int){
        return s2;
    });
    // other code here
    //...
    std::cout << "returned " << f1.get() << '\n';

    auto f2 = p.push([](int){
        throw std::exception();
    });
    // other code here
    //...
    try {
        f2.get();
    }
    catch (std::exception & e) {
        std::cout << "caught exception\n";
    }

    // get thread 0
    auto & th = p.get_thread(0);

    return 0;
}