timer_delete does not cancel the thread to run the function

Bug #489497 reported by Angelo Borsotti
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Expired
Undecided
Unassigned

Bug Description

timer_create(), when told to run a function at time expiration, creates immediately an ancillary thread
(it could have created it when armed, or even better, when expired). When the timer is deleted, the
ancillary thread does not get cancelled. Not even if it was created as detached. That ancillary thread
must instead be terminated, otherwise it wastes resources (and prevents the process to terminate
normally).
Program that shows it:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <signal.h>
#include <unistd.h>
#include <dirent.h>
#include <stddef.h>

// enumerate all threads of this process
static void listthreads(char* str){
    printf("threads %s\n",str);
    char buf[100];
    sprintf(buf,"/proc/%d/task",getpid());
    DIR* dir = opendir(buf);
    int len = offsetof(struct dirent,d_name) +
        pathconf(buf,_PC_NAME_MAX) + 1;
    struct dirent* entryp;
    entryp = malloc(len);
    struct dirent* res;
    for (;;){
        readdir_r(dir,entryp,&res);
        if (res == NULL) break;
        if (entryp->d_name[0] == '.') continue;
        printf(" %s\n",entryp->d_name);
    }
    closedir(dir);
    printf("end of list\n");
}

void timerfunction(sigval_t sigval){
}

int main(int argc, char* argv[]){
    printf("main %d\n",getpid());
    struct sigevent event;
    event.sigev_notify = SIGEV_THREAD;
    event.sigev_notify_function = timerfunction;
    event.sigev_notify_attributes = NULL;
    event.sigev_value.sival_ptr = (void*)pthread_self();
    timer_t timer_id;
    if (timer_create(CLOCK_REALTIME,&event,&timer_id) < 0){
        perror("timer create");
    }
    listthreads("after timer creation");
    struct itimerspec itime; // arm timer
    itime.it_value.tv_sec = 10;
    itime.it_value.tv_nsec = 0;
    itime.it_interval.tv_sec = 0;
    itime.it_interval.tv_nsec = 0;
    if (timer_settime(timer_id,0,&itime,NULL) < 0){
        perror("timer settime");
    }
    listthreads("after timer arming");

    timer_delete(timer_id); // disarm and delete timer
    listthreads("after timer delete");
}

$ gcc timerdelete.c -lrt
$ ./a.out
main 9958
threads after timer creation
    9958
    9959
end of list
threads after timer arming
    9958
    9959
end of list
threads after timer delete
    9958
    9959
end of list

ProblemType: Bug
Architecture: i386
AudioDevicesInUse:
 USER PID ACCESS COMMAND
 /dev/snd/controlC0: angelo 1643 F.... pulseaudio
CRDA: Error: [Errno 2] No such file or directory
Card0.Amixer.info:
 Card hw:0 'NVidia'/'HDA NVidia at 0xfe028000 irq 23'
   Mixer name : 'Realtek ALC888'
   Components : 'HDA:10ec0888,1631e601,00100001'
   Controls : 37
   Simple ctrls : 21
Date: Sat Nov 28 10:24:21 2009
DistroRelease: Ubuntu 9.10
HibernationDevice: RESUME=UUID=335bd2d5-504f-4410-a53a-96814ee336e8
InstallationMedia: Ubuntu 9.10 "Karmic Koala" - Release i386 (20091028.5)
Lsusb:
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 Bus 002 Device 002: ID 046d:c315 Logitech, Inc. Classic New Touch Keyboard
 Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
MachineType: Packard Bell BV IMEDIA 8425
NonfreeKernelModules: nvidia
Package: linux-image-2.6.31-15-generic 2.6.31-15.50
ProcCmdLine: BOOT_IMAGE=/boot/vmlinuz-2.6.31-15-generic root=UUID=4643cae4-fc87-4dec-a73c-04ce2ccfc02a ro quiet splash
ProcEnviron:
 LANG=en_US.UTF-8
 SHELL=/bin/bash
ProcVersionSignature: Ubuntu 2.6.31-15.50-generic
RelatedPackageVersions:
 linux-backports-modules-2.6.31-15-generic N/A
 linux-firmware 1.25
RfKill:
 0: phy0: Wireless LAN
  Soft blocked: no
  Hard blocked: no
SourcePackage: linux
Uname: Linux 2.6.31-15-generic i686
dmi.bios.date: 11/01/2006
dmi.bios.vendor: Phoenix Technologies, LTD
dmi.bios.version: M2N-NM 0401
dmi.board.name: M2N-NM
dmi.board.vendor: Packard Bell BV
dmi.board.version: 1.XX
dmi.chassis.asset.tag: 123456789000
dmi.chassis.type: 3
dmi.chassis.vendor: Packard Bell BV
dmi.chassis.version: Chassis Version
dmi.modalias: dmi:bvnPhoenixTechnologies,LTD:bvrM2N-NM0401:bd11/01/2006:svnPackardBellBV:pnIMEDIA8425:pvrPB80107506:rvnPackardBellBV:rnM2N-NM:rvr1.XX:cvnPackardBellBV:ct3:cvrChassisVersion:
dmi.product.name: IMEDIA 8425
dmi.product.version: PB80107506
dmi.sys.vendor: Packard Bell BV
---
AlsaVersion: Advanced Linux Sound Architecture Driver Version 1.0.21.
Architecture: i386
AudioDevicesInUse:
 USER PID ACCESS COMMAND
 /dev/snd/controlC0: angelo 1356 F.... pulseaudio
CRDA: Error: [Errno 2] No such file or directory
Card0.Amixer.info:
 Card hw:0 'NVidia'/'HDA NVidia at 0xfe028000 irq 23'
   Mixer name : 'Realtek ALC888'
   Components : 'HDA:10ec0888,1631e601,00100001'
   Controls : 37
   Simple ctrls : 21
DistroRelease: Ubuntu 10.04
HibernationDevice: RESUME=UUID=335bd2d5-504f-4410-a53a-96814ee336e8
InstallationMedia: Ubuntu 10.04 LTS "Lucid Lynx" - Release i386 (20100429)
Lsusb:
 Bus 002 Device 002: ID 046d:c315 Logitech, Inc. Classic New Touch Keyboard
 Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
MachineType: Packard Bell BV IMEDIA 8425
NonfreeKernelModules: nvidia
Package: linux (not installed)
ProcCmdLine: BOOT_IMAGE=/boot/vmlinuz-2.6.32-22-generic root=UUID=2258e664-9423-4566-ae33-52c12a4645ec ro quiet splash
ProcEnviron:
 LANG=en_US.utf8
 SHELL=/bin/bash
ProcVersionSignature: Ubuntu 2.6.32-22.33-generic 2.6.32.11+drm33.2
Regression: No
RelatedPackageVersions: linux-firmware 1.34
Reproducible: Yes
RfKill:
 0: phy0: Wireless LAN
  Soft blocked: no
  Hard blocked: no
Tags: lucid needs-upstream-testing
Uname: Linux 2.6.32-22-generic i686
UserGroups: adm admin cdrom dialout lpadmin plugdev sambashare
dmi.bios.date: 11/01/2006
dmi.bios.vendor: Phoenix Technologies, LTD
dmi.bios.version: M2N-NM 0401
dmi.board.name: M2N-NM
dmi.board.vendor: Packard Bell BV
dmi.board.version: 1.XX
dmi.chassis.asset.tag: 123456789000
dmi.chassis.type: 3
dmi.chassis.vendor: Packard Bell BV
dmi.chassis.version: Chassis Version
dmi.modalias: dmi:bvnPhoenixTechnologies,LTD:bvrM2N-NM0401:bd11/01/2006:svnPackardBellBV:pnIMEDIA8425:pvrPB80107506:rvnPackardBellBV:rnM2N-NM:rvr1.XX:cvnPackardBellBV:ct3:cvrChassisVersion:
dmi.product.name: IMEDIA 8425
dmi.product.version: PB80107506
dmi.sys.vendor: Packard Bell BV

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote :
Andy Whitcroft (apw)
tags: added: kernel-karmic
Revision history for this message
Jeremy Foshee (jeremyfoshee) wrote :

Hi Angelo,

This bug was reported a while ago and there hasn't been any activity in it recently. We were wondering if this is still an issue? Can you try with the latest development release of Ubuntu? ISO CD images are available from http://cdimage.ubuntu.com/releases/ .

If it remains an issue, could you run the following command from a Terminal (Applications->Accessories->Terminal). It will automatically gather and attach updated debug information to this report.

apport-collect -p linux 489497

Also, if you could test the latest upstream kernel available that would be great. It will allow additional upstream developers to examine the issue. Refer to https://wiki.ubuntu.com/KernelMainlineBuilds . Once you've tested the upstream kernel, please remove the 'needs-upstream-testing' tag. This can be done by clicking on the yellow pencil icon next to the tag located at the bottom of the bug description and deleting the 'needs-upstream-testing' text. Please let us know your results.

Thanks in advance.

    [This is an automated message. Apologies if it has reached you inappropriately; please just reply to this message indicating so.]

tags: added: needs-kernel-logs
tags: added: needs-upstream-testing
tags: added: kj-triage
Changed in linux (Ubuntu):
status: New → Incomplete
Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : AlsaDevices.txt

apport information

tags: added: apport-collected
description: updated
Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : AplayDevices.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : ArecordDevices.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : BootDmesg.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : Card0.Amixer.values.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : Card0.Codecs.codec.0.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : CurrentDmesg.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : IwConfig.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : Lspci.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : PciMultimedia.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : ProcCpuinfo.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : ProcInterrupts.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : ProcModules.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : UdevDb.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : UdevLog.txt

apport information

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : Re: [Bug 489497] Re: timer_delete does not cancel the thread to run the function

Hi Jeremy,

I have tested the issue with 10.04: it is still there.
I have used apport to collect data and send them.

-Angelo

Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : WifiSyslog.txt

apport information

Revision history for this message
Jeremy Foshee (jeremyfoshee) wrote :

This bug report was marked as Incomplete and has not had any updated comments for quite some time. As a result this bug is being closed. Please reopen if this is still an issue in the current Ubuntu development release http://cdimage.ubuntu.com/daily-live/current/ . Also, please be sure to provide any requested information that may have been missing. To reopen the bug, click on the current status under the Status column and change the status back to "New". Thanks.

[This is an automated message. Apologies if it has reached you inappropriately; please just reply to this message indicating so.]

tags: added: kj-expired
Changed in linux (Ubuntu):
status: Incomplete → Expired
Revision history for this message
Angelo Borsotti (angelo-borsotti) wrote : Re: [Bug 489497] Re: timer_delete does not cancel the thread to run the function

Hello Jeremy,

I do not understand why the bug was marked as incomplete. The bug report
contains all
the information needed to reproduce the problem.
I have included a sample program that shows the bug in it.
I have run today that program on 10.04 and have seen again the same bug.
Unfortunately I do not have a way to install the latest development version,
but unless that specific issue has been addressed in it, it is likely that
the
very same bug is still unsolved.
Could you reopen the bug and mark in it the all the info needed to solve it
is present, or tell me what other info I must provide?

Thank you
-Angelo Borsotti

To post a comment you must log in.