Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84f7f92

Browse files
committed
threadpool
1 parent 70d1364 commit 84f7f92

File tree

10 files changed

+762
-0
lines changed

10 files changed

+762
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ Code With Comments
2222
博客:[在此](http://blog.csdn.net/jcjc918/article/details/44965951)
2323

2424
链接:[webbench](https://github.com/AngryHacker/code-with-comments/tree/master/webbench)
25+
26+
### Threadpool
27+
介绍:基于 pthread 实现的简单线程池
28+
29+
博客:[在此](http://blog.csdn.net/jcjc918/article/details/50395528)
30+
31+
链接:[Threadpool](https://github.com/mbrossard/threadpool)

threadpool/LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2013, Mathias Brossard. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

threadpool/Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
CFLAGS = -D_REENTRANT -Wall -pedantic -Isrc
2+
LDLIBS = -lpthread
3+
4+
ifdef DEBUG
5+
CFLAGS += -g
6+
LDFLAGS += -g
7+
endif
8+
9+
TARGETS = tests/thrdtest tests/heavy tests/shutdown \
10+
libthreadpool.so libthreadpool.a
11+
12+
all: $(TARGETS)
13+
14+
tests/shutdown: tests/shutdown.o src/threadpool.o
15+
tests/thrdtest: tests/thrdtest.o src/threadpool.o
16+
tests/heavy: tests/heavy.o src/threadpool.o
17+
src/threadpool.o: src/threadpool.c src/threadpool.h
18+
tests/thrdtest.o: tests/thrdtest.c src/threadpool.h
19+
tests/heavy.o: tests/heavy.c src/threadpool.h
20+
21+
# Short-hand aliases
22+
shared: libthreadpool.so
23+
static: libthreadpool.a
24+
25+
libthreadpool.so: src/threadpool.c src/threadpool.h
26+
$(CC) -shared -fPIC ${CFLAGS} -o $@ $< ${LDLIBS}
27+
28+
src/libthreadpool.o: src/threadpool.c src/threadpool.h
29+
$(CC) -c -fPIC ${CFLAGS} -o $@ $<
30+
31+
libthreadpool.a: src/libthreadpool.o
32+
ar rcs $@ $^
33+
34+
clean:
35+
rm -f $(TARGETS) *~ */*~ */*.o
36+
37+
test:
38+
./tests/shutdown
39+
./tests/thrdtest
40+
./tests/heavy
41+

threadpool/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[![Build Status](https://travis-ci.org/mbrossard/threadpool.svg?branch=master)](https://travis-ci.org/mbrossard/threadpool)
2+
3+
A simple C thread pool implementation
4+
=====================================
5+
6+
Currently, the implementation:
7+
* Works with pthreads only, but API is intentionally opaque to allow
8+
other implementations (Windows for instance).
9+
* Starts all threads on creation of the thread pool.
10+
* Reserves one task for signaling the queue is full.
11+
* Stops and joins all worker threads on destroy.
12+
13+
Possible enhancements
14+
=====================
15+
16+
The API contains addtional unused 'flags' parameters that would allow
17+
some additional options:
18+
19+
* Lazy creation of threads (easy)
20+
* Reduce number of threads automatically (hard)
21+
* Unlimited queue size (medium)
22+
* Kill worker threads on destroy (hard, dangerous)
23+
* Support Windows API (medium)
24+
* Reduce locking contention (medium/hard)

threadpool/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "threadpool",
3+
"version": "0.1.0",
4+
"repo": "mbrossard/threadpool",
5+
"description": "Simple C Thread pool implementation.",
6+
"keywords": ["thread", "posix"],
7+
"license": "MIT",
8+
"src": ["src/threadpool.c", "src/threadpool.h"]
9+
}

0 commit comments

Comments
 (0)