openframeworks / openframeworks/openFrameworks

ofThread : can't query if thread is actually running - isThreadRunning() misleading

Open
#5,266 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

ofThread has an internal state variable to check if the thread has finished running.

https://github.com/openframeworks/openFrameworks/blob/ac79b88f0c290c7842a3da81b683085f3527eefc/libs/openFrameworks/utils/ofThread.h#L333

It would be handy to let the user access it to decide if the thread is actually done and can be deleted.

In my case I have ofThread objects that I spawn and don't want to join; I want them to die off silently. I need to check when they are done to delete them, but I see no reliable way of doing so unless I keep internal state myself in my ofThread subclass. I think ofThread should be able to offer its state.

I personally find the isThreadRunning() API very misleading, but I understand changing this will be hard due to legacy reasons.

isThreadRunning() can easily return FALSE while the thread is still actually running threadedFunction(); and this is leading to sporadic crashes in my case; as during my housekeeping I try to delete a thread that its supposedly not running but it still is.

I propose opening up access to the state variable threadDone; maybe with something like:

bool isThreadDone(){
    return threadDone;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in libs/openFrameworks/utils/ofThread.h around line 333 and trace how threadDone and isThreadRunning() change during threadedFunction(). Check whether an exposed completion state can be queried safely during the reported cleanup scenario, then verify that callers can distinguish a finished thread before deleting it.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.