openframeworks / openframeworks/openFrameworks
ofThread : can't query if thread is actually running - isThreadRunning() misleading
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.
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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