Bug 20585 - Problems with threading and device access
Problems with threading and device access
Product: Red Hat Linux
Classification: Retired
Component: kernel (Show other bugs)
i386 Linux
high Severity high
: ---
: ---
Assigned To: Michael K. Johnson
Brock Organ
Depends On:
  Show dependency treegraph
Reported: 2000-11-09 10:17 EST by tjfalcone
Modified: 2005-10-31 17:00 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-12-14 22:28:43 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description tjfalcone 2000-11-09 10:17:46 EST
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;
  return NULL;
int main(int argc, char** argv)
  pthread_t tr;
  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;

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.
Comment 1 Arjan van de Ven 2001-01-16 04:33:39 EST
Your test-program seems to have nothing to do with the sounddaemon problem. Your
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.

Note You need to log in before you can comment on or make changes to this bug.