Skip to content

Commit 183e03d

Browse files
committedJun 21, 2019
111
1 parent 0fbf37e commit 183e03d

9 files changed

+17
-17
lines changed
 

‎.ThreadPool.cpp.swo

12 KB
Binary file not shown.

‎.ThreadPool.cpp.swp

12 KB
Binary file not shown.

‎.ThreadTask.h.swp

0 Bytes
Binary file not shown.

‎.test.cpp.swp

0 Bytes
Binary file not shown.

‎ThreadPool.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,14 @@ void *ThreadPool::thr_fn(void *arg)
5757

5858
ThreadPool *pool = work_thr->thread_pool;
5959

60-
std::cout<< "id=" << (work_thr->id) <<"; thread_id="<<work_thr->thread_id << std::endl;
60+
//std::cout<< "id=" << (work_thr->id) <<"; thread_id="<<work_thr->thread_id << std::endl;
6161

6262
while(work_thr->thread_state == WorkThread::WorkState )
6363
{
6464
pthread_mutex_lock(&pool->lock);
6565
pthread_cond_wait( &pool->queue_not_empty, &pool->lock);
66-
std::list<ThreadTask*>::iterator it1;
67-
it1 = (pool->thread_task).erase((pool->thread_task).begin());
68-
69-
ThreadTask *p_task = *it1;
70-
p_task->thread_task_id;
71-
72-
std::cout << "work thread_id=" << p_task->thread_task_id <<std::endl;
73-
66+
std::cout << (*((pool->thread_task).begin()))->thread_task_id<< std::endl;
67+
(pool->thread_task).erase((pool->thread_task).begin());
7468
pthread_mutex_unlock(&pool->lock);
7569
}
7670
return NULL;
@@ -80,7 +74,8 @@ int ThreadPool::add_task(ThreadTask &task)
8074
{
8175
pthread_mutex_lock(&lock);
8276
thread_task.push_back(&task);
83-
pthread_cond_signal(&queue_not_empty);
77+
int flag=pthread_cond_signal(&queue_not_empty);
78+
std::cout << "flag:" << flag<< std::endl;
8479
pthread_mutex_unlock(&lock);
8580
}
8681

‎a.out

34.3 KB
Binary file not shown.

‎tags

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ StopState WorkThread.h /^ StopState$/;" e enum:threadpool::WorkThread::work_sta
1212
ThreadInit ThreadPool.cpp /^int ThreadPool::ThreadInit()$/;" f class:ThreadPool
1313
ThreadPool ThreadPool.cpp /^ThreadPool::ThreadPool(int min_num, int max_num):$/;" f class:ThreadPool
1414
ThreadPool ThreadPool.h /^class ThreadPool$/;" c namespace:threadpool
15-
ThreadTask ThreadTask.h /^class ThreadTask$/;" c namespace:ThreadTask
16-
ThreadTask ThreadTask.h /^namespace ThreadTask$/;" n
15+
ThreadTask ThreadTask.h /^ ThreadTask(int id):thread_task_id(id)$/;" f class:threadpool::ThreadTask
16+
ThreadTask ThreadTask.h /^class ThreadTask$/;" c namespace:threadpool
1717
WorkState WorkThread.h /^ WorkState,$/;" e enum:threadpool::WorkThread::work_state
1818
WorkThread WorkThread.h /^ WorkThread():thread_id(0),thread_state(WorkState),thread_pool(NULL){$/;" f class:threadpool::WorkThread
1919
WorkThread WorkThread.h /^class WorkThread$/;" c namespace:threadpool
@@ -23,7 +23,6 @@ _WORKTHREAD_H_ WorkThread.h 3;" d
2323
_test_h test.h 2;" d
2424
add_task ThreadPool.cpp /^int ThreadPool::add_task(ThreadTask &task)$/;" f class:ThreadPool
2525
busy_thr_num ThreadPool.h /^ int busy_thr_num;$/;" m class:threadpool::ThreadPool
26-
flag ThreadTask.h /^ int flag;$/;" m class:ThreadTask::ThreadTask
2726
id WorkThread.h /^ int id;$/;" m class:threadpool::WorkThread
2827
live_thr_num ThreadPool.h /^ int live_thr_num;$/;" m class:threadpool::ThreadPool
2928
lock ThreadPool.h /^ pthread_mutex_t lock; \/\/本结构$/;" m class:threadpool::ThreadPool
@@ -44,11 +43,12 @@ thread_counter ThreadPool.h /^ pthread_mutex_t thread_counter; \/\/记录忙状
4443
thread_id WorkThread.h /^ pthread_t thread_id;$/;" m class:threadpool::WorkThread
4544
thread_pool WorkThread.h /^ ThreadPool *thread_pool;$/;" m class:threadpool::WorkThread
4645
thread_state WorkThread.h /^ work_state thread_state; $/;" m class:threadpool::WorkThread
47-
thread_task_id ThreadTask.h /^ int thread_task_id;$/;" m class:ThreadTask::ThreadTask
46+
thread_task ThreadPool.h /^ std::list<ThreadTask*> thread_task;$/;" m class:threadpool::ThreadPool
47+
thread_task_id ThreadTask.h /^ int thread_task_id;$/;" m class:threadpool::ThreadTask
4848
threadpool ThreadPool.h /^namespace threadpool$/;" n
49+
threadpool ThreadTask.h /^namespace threadpool$/;" n
4950
threadpool WorkThread.h /^namespace threadpool$/;" n
5051
threadpool_state ThreadPool.h /^enum threadpool_state{ On, Off };$/;" g class:threadpool::ThreadPool
51-
tm ThreadPool.h /^ ThreadTask tm;$/;" m class:threadpool::ThreadPool
5252
wait_exit_thr_num ThreadPool.h /^ int wait_exit_thr_num;$/;" m class:threadpool::ThreadPool
5353
work_state WorkThread.h /^ enum work_state{$/;" g class:threadpool::WorkThread
5454
work_thread ThreadPool.h /^ std::list<WorkThread*> work_thread;$/;" m class:threadpool::ThreadPool

‎test

-200 Bytes
Binary file not shown.

‎test.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ int main()
1515
thread_pool.ThreadInit();
1616

1717
threadpool::ThreadTask t1(1);
18+
19+
t1.thread_task_id = 10;
20+
1821
threadpool::ThreadTask t2(2);
22+
23+
sleep(3);
1924

2025
thread_pool.add_task(t1);
2126

22-
thread_pool.add_task(t2);
27+
// thread_pool.add_task(t2);
2328

2429

2530

26-
sleep(5);
31+
sleep(10);
2732

2833

2934

0 commit comments

Comments
 (0)
Please sign in to comment.