GithubHelp home page GithubHelp logo

antmuse / antthread Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 151.06 MB

My cross-platform thread/process lib, current for Windows & Linux & Andriod.

License: MIT License

C++ 98.37% C 1.61% Batchfile 0.02%
thread process windows linux cross-platform irrlicht android

antthread's Introduction

AntThread V1.0.0.4

A cross platform thread lib, current for Windows&Linux&Andriod.

Usage


#include "IRunnable.h"
#include "CThread.h"
#include "CThreadPool.h"
#include "CProcessManager.h"
#include "CAtomicValue32.h"

namespace irr {

    void AppQuit() {
        c8 key = '\0';
        while('*' != key) {
            printf("@Please input [*] to quit\n");
            scanf("%c", &key);
        }
    }


    //for thread test
    class CWorker : public IRunnable {
        public:
            virtual void run() {
                CThread* td = CThread::getCurrentThread();
                printf("CWorker::run>>thread id = %u\n", td->getID());
                //CThread::sleep(10);
            }
    };

    //for thread test
    void AppWorker(void* param) {
        CAtomicS32& count = *(CAtomicS32*) (param);
        CThread* td = CThread::getCurrentThread();
        printf("AppWorker::>>[thread=%u], [count=%d]\n", td->getID(), ++count);
        CThread::sleep(10);
    }


    //for thread test
    void AppStartThread() {
        CThread td;
        CWorker wk;
        td.start(wk);
        td.join();
    }


    void AppStartThreadPool() {
        CAtomicS32 count;
        const u32 max = 111;
        CThreadPool pool(9);
        pool.start();
        CWorker wk;
        for(u32 i = 0; i < 10; ++i) {
            pool.start(&wk);
        }
        for(u32 i = 0; i < max; ++i) {
            pool.start(AppWorker, (void*) (&count));
        }
        pool.join();
        printf("AppStartThreadPool::>>[count=%d]\n", count.getValue());
    }

    //test process
    void AppStartProcesses() {
        CProcessManager::DProcessParam params;
#if defined(APP_PLATFORM_WINDOWS)
        //params.push_back(io::path("f:\\test.txt"));
        CProcessHandle* proc = CProcessManager::launch("notepad.exe", params);
#else
        CProcessHandle* proc = CProcessManager::launch("/usr/bin/gnome-calculator", params);
#endif
        if(proc) {
            printf("AppStartProcesses success\n");
            proc->wait();
        } else {
            printf("AppStartProcesses failed\n");
        }
    }

}//namespace irr


int main(int argc, char** argv) {
    printf("@1 Start Thread.\n");
    printf("@2 Start Thread Pool.\n");
    printf("@3 Start Process.\n");
    int key = 0;
    scanf("%d", &key);
    switch(key) {
        case 1:
            irr::AppStartThread();
            break;
        case 2:
            irr::AppStartThreadPool();
            break;
        case 3:
            irr::AppStartProcesses();
            break;
        default:
            printf("@unknown command, pls restart.\n");
            break;
    }
    printf("@Test finish.\n");
    irr::AppQuit();
    return 0;
}//main

antthread's People

Contributors

antmuse avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.