You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ok...@apache.org on 2017/05/25 11:20:22 UTC
[trafficserver] branch master updated: spawn_thread with atomic
operation
This is an automated email from the ASF dual-hosted git repository.
oknet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 05cc3df spawn_thread with atomic operation
05cc3df is described below
commit 05cc3df86672cbb16f17e8909c8b471fac618d4a
Author: Oknet Xu <xu...@skyguard.com.cn>
AuthorDate: Wed May 24 21:20:38 2017 +0800
spawn_thread with atomic operation
The eventProcessor.spawn_thread() is used to create a DEDICATED EThread.
The n_dthreads is total number of DEDICATED EThreads. When a new
DEDICATED EThread created, it makes the `all_dthreads[n_dthreads]' point
to the EThread object then do `n_dthreads++'
It is not likes the spawn_event_threads() that only called from main()
before any EThread runs. It is can be called from main() and/or any
EThread.
Therefore there is a race on accessing `all_dthreads[n_dthreads]' and
`n_dthreads++'.
---
iocore/eventsystem/I_EventProcessor.h | 2 +-
iocore/eventsystem/UnixEventProcessor.cc | 12 ++++++++----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/iocore/eventsystem/I_EventProcessor.h b/iocore/eventsystem/I_EventProcessor.h
index 53923d5..5e1d112 100644
--- a/iocore/eventsystem/I_EventProcessor.h
+++ b/iocore/eventsystem/I_EventProcessor.h
@@ -307,7 +307,7 @@ public:
EThread *assign_thread(EventType etype);
EThread *all_dthreads[MAX_EVENT_THREADS];
- int n_dthreads; // No. of dedicated threads
+ volatile int n_dthreads; // No. of dedicated threads
volatile int thread_data_used;
};
diff --git a/iocore/eventsystem/UnixEventProcessor.cc b/iocore/eventsystem/UnixEventProcessor.cc
index 853d347..2b06c84 100644
--- a/iocore/eventsystem/UnixEventProcessor.cc
+++ b/iocore/eventsystem/UnixEventProcessor.cc
@@ -266,13 +266,17 @@ Event *
EventProcessor::spawn_thread(Continuation *cont, const char *thr_name, size_t stacksize)
{
ink_release_assert(n_dthreads < MAX_EVENT_THREADS);
+ int n = ink_atomic_increment((int *)&n_dthreads, 1);
+ ink_release_assert(n < MAX_EVENT_THREADS);
+
Event *e = eventAllocator.alloc();
e->init(cont, 0, 0);
- all_dthreads[n_dthreads] = new EThread(DEDICATED, e);
- e->ethread = all_dthreads[n_dthreads];
- e->mutex = e->continuation->mutex = all_dthreads[n_dthreads]->mutex;
- n_dthreads++;
+ all_dthreads[n] = new EThread(DEDICATED, e);
+ e->ethread = all_dthreads[n];
+ e->mutex = all_dthreads[n]->mutex;
+ cont->mutex = all_dthreads[n]->mutex;
+
e->ethread->start(thr_name, stacksize, nullptr, nullptr, nullptr);
return e;
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].