31
|
1 |
|
|
2 |
// -*- C++ -*- Time-stamp: <04/01/16 21:32:26 ptr>
|
|
3 |
|
|
4 |
|
|
5 |
#include <string>
|
|
6 |
|
|
7 |
//#if defined(_STLP_PTHREADS) || defined(_STLP_WIN32THREADS)
|
|
8 |
|
|
9 |
#ifdef _STLP_PTHREADS
|
|
10 |
#include <pthread.h>
|
|
11 |
#endif
|
|
12 |
|
|
13 |
/*#ifdef _STLP_WIN32THREADS
|
|
14 |
# include <windows.h>
|
|
15 |
#endif*/
|
|
16 |
|
|
17 |
#ifdef MAIN
|
|
18 |
#define string_mt_test main
|
|
19 |
#endif
|
|
20 |
|
|
21 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
22 |
using namespace std;
|
|
23 |
#endif
|
|
24 |
|
|
25 |
string func( const string& par )
|
|
26 |
{
|
|
27 |
string tmp( par );
|
|
28 |
|
|
29 |
return tmp;
|
|
30 |
}
|
|
31 |
|
|
32 |
//#if defined (_STLP_PTHREADS)
|
|
33 |
void *f( void * )
|
|
34 |
//#elif defined (_STLP_WIN32THREADS)
|
|
35 |
//DWORD __stdcall f (void *)
|
|
36 |
//#endif
|
|
37 |
{
|
|
38 |
string s( "qyweyuewunfkHBUKGYUGL,wehbYGUW^(@T@H!BALWD:h^&@#*@(#:JKHWJ:CND" );
|
|
39 |
|
|
40 |
for ( int i = 0; i < 2000000; ++i ) {
|
|
41 |
string sx = func( s );
|
|
42 |
}
|
|
43 |
|
|
44 |
return 0;
|
|
45 |
}
|
|
46 |
|
|
47 |
int string_mt_test( int, char ** )
|
|
48 |
{
|
|
49 |
|
|
50 |
int failures=0;
|
|
51 |
const int nth = 2;
|
|
52 |
//#if defined(_STLP_PTHREADS)
|
|
53 |
pthread_t t[nth];
|
|
54 |
|
|
55 |
for ( int i = 0; i < nth; ++i ) {
|
|
56 |
int res=pthread_create( &t[i], 0, f, 0 );
|
|
57 |
if(0!= res)
|
|
58 |
failures++;
|
|
59 |
}
|
|
60 |
|
|
61 |
for ( int i = 0; i < nth; ++i ) {
|
|
62 |
int res= pthread_join( t[i], 0 );
|
|
63 |
if(0!=res)
|
|
64 |
failures++;
|
|
65 |
}
|
|
66 |
//#endif // _STLP_PTHREADS
|
|
67 |
|
|
68 |
/*#if defined (_STLP_WIN32THREADS)
|
|
69 |
HANDLE t[nth];
|
|
70 |
|
|
71 |
int i; // VC6 not support in-loop scope of cycle var
|
|
72 |
for ( i = 0; i < nth; ++i ) {
|
|
73 |
t[i] = CreateThread(NULL, 0, f, 0, 0, NULL);
|
|
74 |
}
|
|
75 |
|
|
76 |
for ( i = 0; i < nth; ++i ) {
|
|
77 |
WaitForSingleObject(t[i], INFINITE);
|
|
78 |
}
|
|
79 |
#endif*/
|
|
80 |
|
|
81 |
if(failures)
|
|
82 |
return 1;
|
|
83 |
else
|
|
84 |
return 0;
|
|
85 |
}
|
|
86 |
//#else // !_STLP_PTHREADS && !_STLP_WIN32THREADS
|
|
87 |
|
|
88 |
/*int string_mt_test( int, char ** )
|
|
89 |
{
|
|
90 |
return -1;
|
|
91 |
}
|
|
92 |
*/
|
|
93 |
//#endif // _STLP_PTHREADS || _STLP_WIN32THREADS
|