Skip to content

Commit d9d03d2

Browse files
Merge branch 'iss-19' into develop
2 parents c7c290b + f46dc69 commit d9d03d2

File tree

7 files changed

+190
-13
lines changed

7 files changed

+190
-13
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@mainpage
2-
31
# What it does
42

53
IBM's compiler is not implementing all the features of C++11 standard, especially it's lacking the concurrency features that the standard brings. This will at some point be fixed and was therfore looking at a way reduce the effort to switch from a specific implementation to the C++11 standard one. This projetc is the resulting code.:w

cpp-pthread.xcodeproj/project.pbxproj

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
E54543411CAD23690051A313 /* mutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E5EC5B7B1C9C2C6B00E21131 /* mutex.cpp */; };
1515
E54543421CAD23690051A313 /* lock_guard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E519A0E41C9C4B4F00ED113D /* lock_guard.cpp */; };
1616
E54543431CAD23690051A313 /* thread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E519A0FF1C9C7CAB00ED113D /* thread.cpp */; };
17+
E5BF2B651CB13C8100B158E3 /* without-cpp11-pthread-tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E5BF2B631CB13C7700B158E3 /* without-cpp11-pthread-tests.cpp */; };
18+
E5BF2B661CB13C8900B158E3 /* libcpp-pthread.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E5EC5B711C9C2C3000E21131 /* libcpp-pthread.a */; };
1719
E5C4D71D1C9DC8C700D0E18C /* pthread in Headers */ = {isa = PBXBuildFile; fileRef = E5EC5B811C9C2C8B00E21131 /* pthread */; settings = {ATTRIBUTES = (Public, ); }; };
1820
E5EC5B7D1C9C2C6B00E21131 /* condition_variable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E5EC5B791C9C2C6B00E21131 /* condition_variable.cpp */; };
1921
E5EC5B7F1C9C2C6B00E21131 /* mutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E5EC5B7B1C9C2C6B00E21131 /* mutex.cpp */; };
@@ -27,6 +29,13 @@
2729
remoteGlobalIDString = E5EC5B701C9C2C3000E21131;
2830
remoteInfo = "cpp-pthread";
2931
};
32+
E5BF2B611CB13C5A00B158E3 /* PBXContainerItemProxy */ = {
33+
isa = PBXContainerItemProxy;
34+
containerPortal = E5EC5B691C9C2C3000E21131 /* Project object */;
35+
proxyType = 1;
36+
remoteGlobalIDString = E5EC5B701C9C2C3000E21131;
37+
remoteInfo = "cpp-pthread";
38+
};
3039
/* End PBXContainerItemProxy section */
3140

3241
/* Begin PBXCopyFilesBuildPhase section */
@@ -39,12 +48,23 @@
3948
);
4049
runOnlyForDeploymentPostprocessing = 1;
4150
};
51+
E5BF2B581CB13C3D00B158E3 /* CopyFiles */ = {
52+
isa = PBXCopyFilesBuildPhase;
53+
buildActionMask = 2147483647;
54+
dstPath = /usr/share/man/man1/;
55+
dstSubfolderSpec = 0;
56+
files = (
57+
);
58+
runOnlyForDeploymentPostprocessing = 1;
59+
};
4260
/* End PBXCopyFilesBuildPhase section */
4361

4462
/* Begin PBXFileReference section */
4563
E519A0E41C9C4B4F00ED113D /* lock_guard.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = lock_guard.cpp; path = src/lock_guard.cpp; sourceTree = "<group>"; };
4664
E519A0FF1C9C7CAB00ED113D /* thread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = thread.cpp; path = src/thread.cpp; sourceTree = "<group>"; };
4765
E54543351CAD21A30051A313 /* cpp11-pthread-tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "cpp11-pthread-tests"; sourceTree = BUILT_PRODUCTS_DIR; };
66+
E5BF2B5A1CB13C3D00B158E3 /* without-cpp11-pthread-tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "without-cpp11-pthread-tests"; sourceTree = BUILT_PRODUCTS_DIR; };
67+
E5BF2B631CB13C7700B158E3 /* without-cpp11-pthread-tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "without-cpp11-pthread-tests.cpp"; sourceTree = "<group>"; };
4868
E5EC5B711C9C2C3000E21131 /* libcpp-pthread.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libcpp-pthread.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4969
E5EC5B791C9C2C6B00E21131 /* condition_variable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = condition_variable.cpp; path = src/condition_variable.cpp; sourceTree = "<group>"; };
5070
E5EC5B7B1C9C2C6B00E21131 /* mutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = mutex.cpp; path = src/mutex.cpp; sourceTree = "<group>"; };
@@ -60,6 +80,14 @@
6080
);
6181
runOnlyForDeploymentPostprocessing = 0;
6282
};
83+
E5BF2B571CB13C3D00B158E3 /* Frameworks */ = {
84+
isa = PBXFrameworksBuildPhase;
85+
buildActionMask = 2147483647;
86+
files = (
87+
E5BF2B661CB13C8900B158E3 /* libcpp-pthread.a in Frameworks */,
88+
);
89+
runOnlyForDeploymentPostprocessing = 0;
90+
};
6391
E5EC5B6E1C9C2C3000E21131 /* Frameworks */ = {
6492
isa = PBXFrameworksBuildPhase;
6593
buildActionMask = 2147483647;
@@ -73,6 +101,7 @@
73101
E519A0F31C9C64F600ED113D /* tests */ = {
74102
isa = PBXGroup;
75103
children = (
104+
E5BF2B631CB13C7700B158E3 /* without-cpp11-pthread-tests.cpp */,
76105
E5ECB7211CA43E6C0033A42D /* with-cpp11-pthread-tests.cpp */,
77106
);
78107
path = tests;
@@ -93,6 +122,7 @@
93122
children = (
94123
E5EC5B711C9C2C3000E21131 /* libcpp-pthread.a */,
95124
E54543351CAD21A30051A313 /* cpp11-pthread-tests */,
125+
E5BF2B5A1CB13C3D00B158E3 /* without-cpp11-pthread-tests */,
96126
);
97127
name = Products;
98128
sourceTree = "<group>";
@@ -148,6 +178,24 @@
148178
productReference = E54543351CAD21A30051A313 /* cpp11-pthread-tests */;
149179
productType = "com.apple.product-type.tool";
150180
};
181+
E5BF2B591CB13C3D00B158E3 /* without-cpp11-pthread-tests */ = {
182+
isa = PBXNativeTarget;
183+
buildConfigurationList = E5BF2B5E1CB13C3D00B158E3 /* Build configuration list for PBXNativeTarget "without-cpp11-pthread-tests" */;
184+
buildPhases = (
185+
E5BF2B561CB13C3D00B158E3 /* Sources */,
186+
E5BF2B571CB13C3D00B158E3 /* Frameworks */,
187+
E5BF2B581CB13C3D00B158E3 /* CopyFiles */,
188+
);
189+
buildRules = (
190+
);
191+
dependencies = (
192+
E5BF2B621CB13C5A00B158E3 /* PBXTargetDependency */,
193+
);
194+
name = "without-cpp11-pthread-tests";
195+
productName = "without-cpp11-pthread-tests";
196+
productReference = E5BF2B5A1CB13C3D00B158E3 /* without-cpp11-pthread-tests */;
197+
productType = "com.apple.product-type.tool";
198+
};
151199
E5EC5B701C9C2C3000E21131 /* cpp-pthread */ = {
152200
isa = PBXNativeTarget;
153201
buildConfigurationList = E5EC5B751C9C2C3000E21131 /* Build configuration list for PBXNativeTarget "cpp-pthread" */;
@@ -177,6 +225,9 @@
177225
E54543341CAD21A30051A313 = {
178226
CreatedOnToolsVersion = 7.3;
179227
};
228+
E5BF2B591CB13C3D00B158E3 = {
229+
CreatedOnToolsVersion = 7.3;
230+
};
180231
E5EC5B701C9C2C3000E21131 = {
181232
CreatedOnToolsVersion = 7.2.1;
182233
};
@@ -196,6 +247,7 @@
196247
targets = (
197248
E5EC5B701C9C2C3000E21131 /* cpp-pthread */,
198249
E54543341CAD21A30051A313 /* cpp11-pthread-tests */,
250+
E5BF2B591CB13C3D00B158E3 /* without-cpp11-pthread-tests */,
199251
);
200252
};
201253
/* End PBXProject section */
@@ -213,6 +265,14 @@
213265
);
214266
runOnlyForDeploymentPostprocessing = 0;
215267
};
268+
E5BF2B561CB13C3D00B158E3 /* Sources */ = {
269+
isa = PBXSourcesBuildPhase;
270+
buildActionMask = 2147483647;
271+
files = (
272+
E5BF2B651CB13C8100B158E3 /* without-cpp11-pthread-tests.cpp in Sources */,
273+
);
274+
runOnlyForDeploymentPostprocessing = 0;
275+
};
216276
E5EC5B6D1C9C2C3000E21131 /* Sources */ = {
217277
isa = PBXSourcesBuildPhase;
218278
buildActionMask = 2147483647;
@@ -232,6 +292,11 @@
232292
target = E5EC5B701C9C2C3000E21131 /* cpp-pthread */;
233293
targetProxy = E545433E1CAD22180051A313 /* PBXContainerItemProxy */;
234294
};
295+
E5BF2B621CB13C5A00B158E3 /* PBXTargetDependency */ = {
296+
isa = PBXTargetDependency;
297+
target = E5EC5B701C9C2C3000E21131 /* cpp-pthread */;
298+
targetProxy = E5BF2B611CB13C5A00B158E3 /* PBXContainerItemProxy */;
299+
};
235300
/* End PBXTargetDependency section */
236301

237302
/* Begin XCBuildConfiguration section */
@@ -253,6 +318,24 @@
253318
};
254319
name = Release;
255320
};
321+
E5BF2B5F1CB13C3D00B158E3 /* Debug */ = {
322+
isa = XCBuildConfiguration;
323+
buildSettings = {
324+
ALWAYS_SEARCH_USER_PATHS = NO;
325+
CLANG_ANALYZER_NONNULL = YES;
326+
PRODUCT_NAME = "$(TARGET_NAME)";
327+
};
328+
name = Debug;
329+
};
330+
E5BF2B601CB13C3D00B158E3 /* Release */ = {
331+
isa = XCBuildConfiguration;
332+
buildSettings = {
333+
ALWAYS_SEARCH_USER_PATHS = NO;
334+
CLANG_ANALYZER_NONNULL = YES;
335+
PRODUCT_NAME = "$(TARGET_NAME)";
336+
};
337+
name = Release;
338+
};
256339
E5EC5B731C9C2C3000E21131 /* Debug */ = {
257340
isa = XCBuildConfiguration;
258341
buildSettings = {
@@ -289,7 +372,7 @@
289372
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
290373
GCC_WARN_UNUSED_FUNCTION = YES;
291374
GCC_WARN_UNUSED_VARIABLE = YES;
292-
HEADER_SEARCH_PATHS = "";
375+
HEADER_SEARCH_PATHS = "$(SRCROOT)/../include";
293376
MACOSX_DEPLOYMENT_TARGET = 10.11;
294377
MTL_ENABLE_DEBUG_INFO = YES;
295378
ONLY_ACTIVE_ARCH = YES;
@@ -328,7 +411,7 @@
328411
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
329412
GCC_WARN_UNUSED_FUNCTION = YES;
330413
GCC_WARN_UNUSED_VARIABLE = YES;
331-
HEADER_SEARCH_PATHS = "";
414+
HEADER_SEARCH_PATHS = "$(SRCROOT)/../include";
332415
MACOSX_DEPLOYMENT_TARGET = 10.11;
333416
MTL_ENABLE_DEBUG_INFO = NO;
334417
SDKROOT = macosx;
@@ -374,6 +457,14 @@
374457
defaultConfigurationIsVisible = 0;
375458
defaultConfigurationName = Release;
376459
};
460+
E5BF2B5E1CB13C3D00B158E3 /* Build configuration list for PBXNativeTarget "without-cpp11-pthread-tests" */ = {
461+
isa = XCConfigurationList;
462+
buildConfigurations = (
463+
E5BF2B5F1CB13C3D00B158E3 /* Debug */,
464+
E5BF2B601CB13C3D00B158E3 /* Release */,
465+
);
466+
defaultConfigurationIsVisible = 0;
467+
};
377468
E5EC5B6C1C9C2C3000E21131 /* Build configuration list for PBXProject "cpp-pthread" */ = {
378469
isa = XCConfigurationList;
379470
buildConfigurations = (

cpp-pthread.xcodeproj/xcuserdata/herbert.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99
<key>isShown</key>
1010
<true/>
1111
<key>orderHint</key>
12-
<integer>0</integer>
12+
<integer>5</integer>
1313
</dict>
1414
<key>cpp11-pthread-tests.xcscheme</key>
1515
<dict>
1616
<key>isShown</key>
1717
<true/>
1818
<key>orderHint</key>
19-
<integer>4</integer>
19+
<integer>6</integer>
20+
</dict>
21+
<key>without-cpp11-pthread-tests.xcscheme</key>
22+
<dict>
23+
<key>orderHint</key>
24+
<integer>7</integer>
2025
</dict>
2126
</dict>
2227
<key>SuppressBuildableAutocreation</key>
@@ -31,6 +36,11 @@
3136
<key>primary</key>
3237
<true/>
3338
</dict>
39+
<key>E5BF2B591CB13C3D00B158E3</key>
40+
<dict>
41+
<key>primary</key>
42+
<true/>
43+
</dict>
3444
<key>E5EC5B701C9C2C3000E21131</key>
3545
<dict>
3646
<key>primary</key>

doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ FILTER_SOURCE_PATTERNS =
978978
# (index.html). This can be useful if you have a project on for instance GitHub
979979
# and want to reuse the introduction page also for the doxygen output.
980980

981-
USE_MDFILE_AS_MAINPAGE =
981+
USE_MDFILE_AS_MAINPAGE =README.md
982982

983983
#---------------------------------------------------------------------------
984984
# Configuration options related to source browsing

include/pthread/condition_variable.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ namespace pthread {
112112
*/
113113
cv_status wait_for (mutex &mtx, int millis );
114114

115-
cv_status wait_for (lock_guard<pthread::mutex> &lck, int millis );
116-
117115
/** @see #wait_for (mutex &, int)
118116
*/
119117
cv_status wait_for (lock_guard<pthread::mutex> &lck, int millis );

include/pthread/thread.hpp

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,63 @@ namespace pthread {
162162
thread_status _status;
163163
};
164164

165+
/** base class of a thread.
166+
*
167+
* utility class, that wraps a thread.
168+
* <pre><code>
169+
class worker: public pthread::abstract_thread {
170+
public:
171+
172+
worker(const std::string m = "anonymous worker", int sleep = 2*1000): msg(m), _sleep(sleep){
173+
};
174+
175+
~worker(){
176+
};
177+
178+
void run() __NOEXCEPT__ __OVERRIDE__ {
179+
{ // critical section scope
180+
pthread::lock_guard<pthread::mutex> lck(mtx);
181+
182+
bool stop_waiting = true; // if lambda syntax is not availbale then use this kind of implementation
183+
auto delay = _sleep; // use sleep seconds to calculate point in time timeout
184+
while ( ! (stop_waiting = (counter >= 10000)) && (condition.wait_for(mtx, delay) == pthread::cv_status::no_timeout)){
185+
delay = -1 ; // if timeout millis is negatif, then we keep last timeout calculation.
186+
}
187+
188+
if ( counter >= 10000 ) {
189+
message("worker class, counter >= 10000");
190+
} else {
191+
message("worker class, counter < 10000");
192+
}
193+
} // end of critical section
194+
195+
pthread::this_thread::sleep(200);
196+
};
197+
198+
private:
199+
std::string msg ;
200+
int _sleep;
201+
};
202+
203+
int main(int argc, const char * argv[]) {
204+
205+
pthread::thread_group threads(true); // indicate that we want to join referenced threads when deallocating this instance.
206+
for (auto x = 10 ; x > 0 ; x--){
207+
threads.add( new worker("herbert"));
208+
}
209+
210+
threads.start(); // start running all threads
211+
212+
for ( auto x = 20000 ; x > 0 ; x--){
213+
pthread::lock_guard<pthread::mutex> lck(mtx);
214+
counter++ ;
215+
}
216+
217+
condition.notify_all();
218+
}
219+
220+
* </code></pre>
221+
*/
165222
class abstract_thread: public runnable {
166223
public:
167224
virtual ~abstract_thread();
@@ -174,19 +231,23 @@ namespace pthread {
174231
pthread::thread *_thread;
175232
};
176233

177-
/** group (list) of abstract_threads.
234+
/** Group of abstract_threads pointers.
178235
*
179-
* method in this class apply's to all threads in the group. this means that when an thread_group instance is deallocated, all threads it references are deleted.
236+
* This helper class is in charge of handling group of threads as a whole. Method in this class apply to all threads in the group.
237+
*
238+
* To avoid memory lose of resources, a thread_group deletes the thread that were registered/added.
180239
*/
181240
class thread_group{
182241
public:
183242
/** Setup a thread container/list.
184243
*
185-
* @param destructor_joins_first if true then destructor tries to join all regsitered threads before deleting thread instances.
244+
* @param destructor_joins_first if true then destructor tries to wait for all registered threads to join the calling one before deleting thread instances.
186245
*/
187246
thread_group( bool destructor_joins_first = false ) __NOEXCEPT__;
188247

189-
/** delete all threads referenced by the thread_group.
248+
/** delete all abstract_thread referenced by the thread_group.
249+
*
250+
* If destructor_joins_first is true then the method abstract_thread::join() is called before deleting the referenced abstract_thread.
190251
*/
191252
virtual ~thread_group();
192253

@@ -203,6 +264,10 @@ namespace pthread {
203264
*/
204265
void join();
205266

267+
/** return if thread_group should wait for all referenced abstract_thread terminate
268+
*/
269+
const bool destructor_joins_first(){ return _destructor_joins_first;};
270+
206271
private:
207272
std::list<pthread::abstract_thread*> _threads;
208273
bool _destructor_joins_first;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// main.cpp
3+
// without-cpp11-pthread-tests
4+
//
5+
// Created by herbert koelman on 03/04/2016.
6+
// Copyright © 2016 urbix-software. All rights reserved.
7+
//
8+
9+
#include <iostream>
10+
11+
int main(int argc, const char * argv[]) {
12+
// insert code here...
13+
std::cout << "Hello, World!\n";
14+
return 0;
15+
}

0 commit comments

Comments
 (0)