Giter Site home page Giter Site logo

dispatcher's Introduction

G.O.D: Grand Object-bound Dispatcher

G.O.D is a high performance non-blocking task dispatcher which guarantees class member functions' execution sequence

FEATURES

  • Designed for multi-platform by using C++11 standard
  • Visual Studio Solutions for now, but you can easily use in *NIX environment (Just #include relevant files)
  • Lock-free algorithms (non-blocking)
  • Using custom STL allocator
  • Deferred task execution using Timer
  • Simple code-base for easy to understand (easy to adapt to other projects)

REAL WORLD EXAMPLES

BRANCHES

  • base_version: basic version for educational purposes
  • bind_version: std::bind is adopted instead of a custom Job class interface
  • LB_version: load-balancing among worker-threads (new arrival!)

HOW TO USE

// First, you can attach G.O.D (AsyncExecutable) to an object like this:
class TestObject : public AsyncExecutable
{
public:

	void TestFunc(double a, int b)
	{
	  // do something... 
	  // (e.g.) someobj->DoAsync(...);
	}
	
	// ... ...
};

// somewhere ... 
auto testobj = std::make_shared<TestObject>(); ///< new TestObject;

// And then, make your own worker thread which implements Runnable::Run() like this:
class TestWorkerThread : public Runnable
{
public:
	virtual bool Run()
	{
	   // Now, you can call a member function like this:
	   testobj->DoAsync(&TestObject::TestFunc, 100.123, 456);

	   // or, deferred execution 1000ms later like this:
	   testobj->DoAsyncAfter(1000, &TestObject::TestFunc, 100.123, 456);
	   
	   // ... ...
	}
};

// Lastly, run worker-threads at the main() function
JobDispatcher<TestWorkerThread> workerService(WORKER_COUNT);
workerService.RunWorkerThreads();

For more information, just see self-explaning DispatcherTest.cpp

WARNING!

  1. You should use x64 mode due to std::atomic variable alignment
  2. You should guarantee the lifetime (i.e. AsyncExecutable::mRefCount > 0) of an object inherited from AsyncExecutable
  3. Be careful to use DoAsync(...) in a blockable LOCK (critical section). It can cause deadlock...

dispatcher's People

Contributors

leafbird avatar zeliard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dispatcher's Issues

교수님, 질문입니다.

프로그램이 실행중일 때, 하나의 실행기(코드상으로는 AsyncExecutable 의 한 인스턴스) 안에서 수행중인 어떤 Job이 있다고 가정합니다. 근데 이 Job의 내용 중에 다른 실행기 인스턴스로 async job을 queueing해야 하는 상황입니다.
이 때 만약 새 job이 queueing되는 두 번째 실행기를 다른 스레드가 점유하고 처리중이었다면, 단순하게 큐에만 쌓아놓고 되돌아오겠지만, 그렇지 않고 큐가 비어 있었다면 이 실행기는 대기 상태가 됩니다. queueing시킨 스레드가 현재 점유중인 첫번째 실행기를 모두 처리하고 나면 잠시 대기시켜 두었던 두 번째 실행기에 대한 처리를 하게 됩니다.

이를 위해 ThreadLocal.h에는 LExecuterList라는 FIFO 자료구조가 존재하고 있습니다.

extern thread_local ExecuterListType*   LExecuterList;

이제 질문인데요.
LExecuterList를 스레드 로컬로 설정하신 이유가 있으신가요?
그렇지 않고 대기중인 실행기 리스트를 글로벌 싱글턴으로 만들어서(MPMC로 동작해야겠지요)
여유가 있는 다른 스레드가 좀 더 빨리 대기상태의 실행기를 가져가 처리할 수 있게 구성해도 되지 않을까요?

그리고 두 번째 질문입니다만,
언제 박일님이랑 같이 해서 점심식사 한 번 어떠신지요? ㅎ

교수님, 2의 승수 체크하는 코드 질문입니다

교수님 안녕하세요.
질문이 있어용.

void* __powerof2check__[((POOL_MAX_SIZE & POOL_SIZE_MASK) == 0x0) & 0x1];

오브젝트 풀에서 사이즈가 2의 승수인지 컴파일 타임 체크하는 코드 있잖아요.
이거 그냥 static_assert로 바꿀 순 없는 건가요?

static_assert((POOL_MAX_SIZE & POOL_SIZE_MASK) == 0x0, "pool's size must be power of 2");

요렇게 말입니다.

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.