I am having problems with g++ and pthreads, which is affecting the way the artsd sound daemon (in KDE 2.0) accesses the sound device. My understanding of the way the daemon works is this: when a user starts a session (e.g., by placing "startkde" in her .xinitrc), the sound daemon artsd is started. It is responsible for multiplexing sound events. It accomplishes this, in part, by spawning threads which listen to various "sound-requiring" programs, like KDE's "kaiman." The problem is that the kernel doesn't seem to like it when different threads access the same device, even if they are all associated to the same process. For example, I have run the following test code: #include <pthread.h> #include <iostream.h> #include <stdio.h> #include <unistd.h> static void *playerThread(void *arg) { cout << "In playerThread now." << endl; while(1) { cout << "Here is thread A" << endl; sleep(5); } return NULL; } int main(int argc, char** argv) { pthread_t tr; sleep(10); if (pthread_create(&tr,NULL,playerThread,NULL) != 0) { perror("Error in thread."); } sleep(2); // critical delay time!! while(1) { cout << "Thread main - sleeping for ten seconds." << endl; sleep(10); } } By adjusting the "critical delay time," I can make either the main thread or the spawned thread print to cout, and, rarely, get both to print, though only intermittently. If I change the code so that the thread prints to cerr, then the code does just what it is supposed to. I am assuming that this is a bug in 7.0, since the same code in RH 6.1 works exactly the way it is supposed to, and esd (the Enlightenment sound daemon) appears to multiplex sound events properly on this system. (I am running Gnome on the RH 6.1 system and KDE 2.0 on the RH 7.0 system, just for kicks.) Please let me know what can be done to correct this problem, as I am sure that I am not the only person experiencing it. Thanks in advance.
Your test-program seems to have nothing to do with the sounddaemon problem. Your program suffers from some issue in stdout buffering that may or may not be bug in glibc, I bet once you add a \n to the textstrings the issue is gone.