Skip to content

[question] High CPU usage when calling ABT_cond_timedwait from a non-ULT thread #404

@tsukada-ascade

Description

@tsukada-ascade

Summary

I am using ABT_cond_timedwait() in a single-threaded program where the main() thread calls it directly to wait for a condition with a timeout (no other thread signals the condition, so it always times out). However, I notice that the program consumes 100% CPU during the wait, which is unexpected—I would have assumed it to be blocking with minimal CPU usage.

Reproducer Overview

#include <assert.h>
#include <stdio.h>
#include <time.h>
#include <abt.h>

ABT_mutex_memory mutex_mem = ABT_MUTEX_INITIALIZER;
ABT_cond_memory cond_mem = ABT_COND_INITIALIZER;

int main(int argc, char *argv[])
{
    ABT_mutex mutex = ABT_MUTEX_MEMORY_GET_HANDLE(&mutex_mem);
    ABT_cond cond = ABT_COND_MEMORY_GET_HANDLE(&cond_mem);
    struct timespec ts;
    int ret;

    ABT_init(argc, argv);

    clock_gettime(CLOCK_REALTIME, &ts);
    ts.tv_sec += 30;

    ABT_mutex_lock(mutex);
    ret = ABT_cond_timedwait(cond, mutex, &ts); // Always times out
    ABT_mutex_unlock(mutex);

    ABT_finalize();
    return 0;
}

Questions

  1. Is ABT_cond_timedwait() expected to work correctly when called from a non-ULT thread, such as the main POSIX thread (i.e., outside of a user-level thread)?
  2. If not, is this limitation documented anywhere? I couldn’t find any explicit mention of this constraint in the official documentation.
  3. Is the high CPU usage in this case an expected behavior or a bug?

Any clarification would be greatly appreciated.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions