Release a C ++ multi-thread library in Linux

Source: Internet
Author: User

Release a C ++ multi-thread library for Linux written in my spare time. This library contains less than 1000 lines.Source codeIt encapsulates common pthreads functions (mutex, condition variable, thread), implements a simple thread pool, and compiles blockingqueue and countdownlatch in accordance with the Java concurrent package. Every class in the Library provides an example.

The content of this library:

    • Atomic integer operations: atomicint32 and atomicint64
    • Thread
    • Thread Pool, threadpool
    • Mutexlock, mutexlockguard, and condition
    • Exception base class with stack trace information
    • Similar to Java concurrent blockingqueue and countdownlatch
    • Singleton and threadlocal

Note: I did not provide the semaphore encapsulation. In the future, the read/write lock encapsulation may be added, if I use it in my blog.

The interfaces of thread and threadpool adopt the style advocated in "replace virtual functions with boost: function and boost: bind". Inheritance and base classes are not used.

Note that currentthread has a thread local variable t_threadname, which is used to print the thread name during debugging and Analysis of core dump. For example:

(GDB) p'muduo: currentthread: t_threadname'
$4 = 0x4057fe "threadpool2"

For the use of mutexlock, mutexlockguard, and condition, see common programming models of multi-threaded servers.

For the example of countdownlatch, see test/blockingqueue_test.cc.

Git: http://github.com/chenshuo/recipes

Browsing SourceCode: Http://github.com/chenshuo/recipes/tree/master/thread/

This library has been compiled and tested under Debian squeeze and Ubuntu 10.04 lts for x86 and x86-64 platforms.

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.