openframeworks / openframeworks/openFrameworks

Bug? ofThreadChannel can have size of 0 when tryReceive continues

Open
#4,946 12 comments 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

Hey!

image
I'm getting crashes on this line because queue is empty

I have stable operation when I'm using tryReceive without the timeout, but it crashes on 5% of calls when I use this function instead.
To note, only 1 thread is receiving (so it isn't unlocking elsewhere after i've emptied the queue). Also perhaps note that multiple threads are sending, but that doesn't seem to be unsupported operation. Also this isn't an edited version with size or anything like that.

Perhaps condition.wait_for can just return true for other reasons? Or something else is unlocking.
Anyway, the fix here is to check again if the queue is empty before entering the scope with swap

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 by locating the ofThreadChannel implementation and the tryReceive path, then inspect how condition.wait_for and the queue swap interact. Reproduce the timeout case if possible and verify that the queue is checked before swapping, including behavior with multiple senders and one receiver.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.