Пример #1
0
// main ///////////////////////////////////////////////////////////////////////
int main(int argc, const char * argv[])
{
    int i;
    pthread_t threads[1000];
    Singleton * theInstance = Singleton::Instance();
    
    Singleton * myOtherInstance = Singleton::Instance();

    for (i=0; i<1000; i++) {
        pthread_create(&threads[i], NULL, &myThreadCode, NULL);
    }
    
    for (i=0; i<1000; i++) {
        pthread_join(threads[i], NULL);
    }
    
    cout << "The shared value is: " << theInstance->getSharedValue() << endl;
    
    // since this it is a Singleton class ... the value should be the same
    cout << "The other shared value is: " << myOtherInstance->getSharedValue() << endl;
    
    return 0;
}