#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

int balance = 1000;

void* deposit(void *arg)
{
        int i;
        for(i=0; i<1e7; ++i)
                ++balance;
        return NULL;
}

void* withdraw(void *arg)
{
        int i;
        for(i=0; i<1e7; ++i)
                --balance;
        return NULL;
}

int main()
{
        pthread_t t1, t2;

        pthread_create(&t1, NULL, deposit, (void*)1);
        pthread_create(&t2, NULL, withdraw, (void*)2);

        pthread_join(t1, NULL);
        pthread_join(t2, NULL);

        printf("ending balance = %d\n", balance);
        return 0;
}
