stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_string/src/string_mt.cpp
changeset 31 ce057bb09d0b
child 34 5fae379060a7
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17  
       
    18 // -*- C++ -*- Time-stamp: <04/01/16 21:32:26 ptr>
       
    19 
       
    20 
       
    21 #include <string>
       
    22 
       
    23 //#if defined(_STLP_PTHREADS) || defined(_STLP_WIN32THREADS)
       
    24 
       
    25 #ifdef _STLP_PTHREADS
       
    26 #include <pthread.h>
       
    27 #endif
       
    28 
       
    29 /*#ifdef _STLP_WIN32THREADS
       
    30 # include <windows.h>
       
    31 #endif*/
       
    32 
       
    33 #ifdef MAIN
       
    34 #define string_mt_test main
       
    35 #endif
       
    36 
       
    37 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
       
    38 using namespace std;
       
    39 #endif
       
    40 
       
    41 string func( const string& par )
       
    42 {
       
    43   string tmp( par );
       
    44 
       
    45   return tmp;
       
    46 }
       
    47 
       
    48 //#if defined (_STLP_PTHREADS)
       
    49 void *f( void * )
       
    50 //#elif defined (_STLP_WIN32THREADS)
       
    51 //DWORD __stdcall f (void *)
       
    52 //#endif
       
    53 {
       
    54   string s( "qyweyuewunfkHBUKGYUGL,wehbYGUW^(@T@H!BALWD:h^&@#*@(#:JKHWJ:CND" );
       
    55 
       
    56   for ( int i = 0; i < 2000000; ++i ) {
       
    57     string sx = func( s );
       
    58   }
       
    59 
       
    60   return 0;
       
    61 }
       
    62 
       
    63 int string_mt_test( int, char ** )
       
    64 {
       
    65 
       
    66   int failures=0;
       
    67   const int nth = 2;
       
    68 //#if defined(_STLP_PTHREADS)
       
    69   pthread_t t[nth];
       
    70 
       
    71   for ( int i = 0; i < nth; ++i ) {
       
    72     int res=pthread_create( &t[i], 0, f, 0 );
       
    73     if(0!= res)
       
    74       failures++;
       
    75   }
       
    76 
       
    77   for ( int i = 0; i < nth; ++i ) {
       
    78      int res= pthread_join( t[i], 0 );
       
    79     if(0!=res)
       
    80        failures++;
       
    81   }
       
    82 //#endif // _STLP_PTHREADS
       
    83 
       
    84 /*#if defined (_STLP_WIN32THREADS)
       
    85   HANDLE t[nth];
       
    86 
       
    87   int i; // VC6 not support in-loop scope of cycle var
       
    88   for ( i = 0; i < nth; ++i ) {
       
    89     t[i] = CreateThread(NULL, 0, f, 0, 0, NULL);
       
    90   }
       
    91 
       
    92   for ( i = 0; i < nth; ++i ) {
       
    93     WaitForSingleObject(t[i], INFINITE);
       
    94   }
       
    95 #endif*/
       
    96 
       
    97 if(failures)
       
    98    return 1;
       
    99 else   
       
   100   return 0;
       
   101 }
       
   102 //#else // !_STLP_PTHREADS && !_STLP_WIN32THREADS
       
   103 
       
   104 /*int string_mt_test( int, char ** )
       
   105 {
       
   106   return -1;
       
   107 }
       
   108 */
       
   109 //#endif // _STLP_PTHREADS || _STLP_WIN32THREADS