#include #include using namespace std; volatile int a = 0, b = 0; void* suma(void*) { while (true) { a = a + 1; b = b + 1; } return NULL; } void* resta(void*) { while (true) { a = a - 1; b = b - 1; } return NULL; } void* pinta(void*) { while (true) { cout << "a = " << a << "\t b = " << b << endl; pthread_yield(); } return NULL; } int main() { pthread_t ids, idr, idp; pthread_create(&ids, NULL, suma, NULL); pthread_create(&idr, NULL, resta, NULL); pthread_create(&idp, NULL, pinta, NULL); pthread_join(ids, NULL); pthread_join(idr, NULL); pthread_join(idp, NULL); }