#include #include #include #include #include "threadracelock.h" using namespace std; int main (int argc, char **argv) { pthread_t a, b; //pthread_t is just the data structure that stores the thread information pthread_create (&a,nullptr,A,nullptr); //this creates a thread and starts it going. //the a is the thread data structure for this particular thread. A is the method that this thread should run. //That first nullptr represents the parameter for the A method, and the second nullptr represents a pointer //to what the A method will return. //pthread_create starts a thread running on method A, but my program in main here still continues. pthread_create (&b,nullptr,B,nullptr); pthread_join (a,NULL); //join means I wait for that thread to die pthread_join (b,NULL); return 0; } void *A (void *x) {//thread methods ALWAYS take a generic pointer as a parameter and return a generic pointer as a result pthread_mutex_lock (&lock1); for (int i=0; i < 1000; i++) cout << "Thread A" << endl; pthread_mutex_unlock (&lock1); return nullptr; } void *B (void *x) {//thread methods ALWAYS take a generic pointer as a parameter and return a generic pointer as a result pthread_mutex_lock (&lock1); for (int i=0; i < 1000; i++) cout << "Thread B" << endl; pthread_mutex_unlock (&lock1); return nullptr; }