// driver_main.cpp #include "common/config.h" #include "socket_driver.h" #include "comm_driver.h" #include "thread_functions.h" int main(int argc, char *argv[]) { SocketDriver socketdriver; CommDriver commdriver; BOOL shutdown = false; pthread_attr_t attr; pthread_t driver_thread, process_thread, comm_thread; sem_t have_work; // initialize the semaphore for thread synchronization if(sem_init(&have_work, 0, 0)) { // bad, we got a return value from sem_init sil_log::log("main(): semaphore initialization error"); exit(SEMAPHORE_ERROR); } socketdriver.initialize(MUDPORT); commdriver.initialize(COMPORT); sil_log::log("socketdriver and commdriver initialized"); // set up the data shared between threads ThreadData tData; tData.driver = &socketdriver; tData.comm = &commdriver; tData.semafor = &have_work; tData.shutdown = &shutdown; // initialize and start our threads pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_create(&driver_thread, NULL, &thread_driver_func, (void *)&tData); pthread_create(&process_thread, &attr, &thread_process_func, (void *)&tData); pthread_create(&comm_thread, &attr, &thread_comm_func, (void *)&tData); // wait for driver thread to rejoin (aka we had a problem or shutdown) pthread_join(driver_thread, NULL); // allow any listening threads to close nicely shutdown = true; // wait for any threads if they are still running //pthread_cancel(process_thread); // do this instead? pthread_join(comm_thread, NULL); pthread_join(process_thread, NULL); return 0; }