Using the Golang in C + +

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The Open source project Cpp_features provides a stackful association libraries that imitates the Golang process. The Golang can be used in C + +, presumably in the syntax:

  1  #include <iostream> 2   3  void   foo ()   4  {  5  std::cout <<  " foo  "  << Std::endl;   "   7   8  co_main ()   9  { 10   go foo;  11 } 

What, is grammar like Golang? The following is the readme for this project

Coroutine is a scheduling stackful co-Libraries written using c++11, and a powerful parallel programming library
Currently supports two platforms:

Linux   (GCC4.8+)Win7-64bit (VS2013/2015)

Use Coroutine to write parallel programs that can be like Golang, Erlang, and other concurrency languages
Developed quickly and logically concise, but also have C + + native performance advantages, fish and bear paw can be both.

Coroutine has the following features:
* 1. Provide Golang general function powerful, write code based on Corontine, can write simple code in a synchronous way, and get asynchronous performance,
* 2. Support the massive process, create 1 million co-processes only need to use 1GB of memory
* 3. Allow users to freely control the scheduling point, arbitrarily change the number of scheduling threads;
* 4. Support multi-thread scheduling process, easy to write parallel code, efficient parallel scheduling algorithm, can effectively utilize multiple CPU cores
* 5. You can make the third-party library of linked-to-program synchronization become an asynchronous call, which greatly improves its performance.
No more worrying. Some DB officials do not provide asynchronous driver, such as Hiredis, Mysqlclient, which can be used directly by the client driver, and can get the performance of not losing to asynchronous driver.
* 6. Dynamic links and static links are all supported, making it easy to use c++11 's user static chaining to deliver executables and deploy to low-version Linux systems.
* 7. Provide Co_mutex, timers, channel and other features to help users to write programs more easily.
* 8. Strong network performance, beyond the ASIO asynchronous model, especially in the processing of small packets and multi-threaded parallelism is very powerful.

    • If you find any bug, have good suggestions, or use the unknown, you can submit to issue, you can also contact the author directly:
      email:289633152@qq.com QQ Exchange Group: 296561497

    • Coroutine/samples directory has a lot of sample code, including detailed instructions, so that users can gradually learn how to use the Coroutine library.

Compilation and use of Coroutine :

  • Linux:
    0. If you have installed Ucorf, then you have installed Coroutine, you can skip the 1th step.
    1. Compile the installation using CMake:

        $ mkdir build    $ cd build    $ cmake .. -DCMAKE_BUILD_TYPE=RELEASE    $ sudo make install

    If you want to compile a debug version, you only need to cmake that line of command into:

        $ cmake ..

    2. When using a dynamic link, be sure to link libcoroutine.so first and link libdl.so. For example:

        g++ -std=c++11 test.cpp -lcoroutine -ldl [-lother_libs]

    3. When used as a static link, simply link libcoroutine.a and do not require the first one to be linked, but require LIBC.A to be linked at the end. For example:

        g++ -std=c++11 test.cpp -lcoroutine -static -static-libgcc -static-libstdc++
  • Windows:
    1. Download submodules using git submodule update–init
    2. Enter the coroutine/win_patch/vs2015 directory, open the Coroutine.sln, do not need to compile the entire solution, just compile Coroutine project. The test project is dependent on boost-x64, if you want to compile, compile the 64bit boost library first:
    Compile parameters:

       bjam.exe address-model=64 --build-type=compelete

    Compile at least the system and thread two libraries, and then adjust the path of the reference boost in the project settings
    3. Compile the Coroutine project (the default project configuration is temporarily configured only for version x64-debug-mt, you need to modify the project configuration by yourself)
    4. You need to add two include directories when using: Coroutine and Coroutine/win_patch

Network library:

    • Network library based on Coroutine, supporting the UDP/TCP protocol in the networks directory

RPC Framework:

      • High-performance general purpose RPC Framework Ucorf based on Coroutine and network, suitable for building large distributed server side, open Source address: Https://github.com/yyzybb537/ucorf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.