|
Re: Lego NXT -- NXC blocking bluetooth IO
I spent a couple hours debugging an issue where threads would randomly crash on it. I thought it could be a race condition, but only two variables are shared between threads, and reads/writes are atomic (boolean).
I then found the -safecall option to nbc. This fixed it.
From now on, my code will have to grab a mutex just to run. I hope Wait() is multithread-safe, but if it isn't, I can write my own (I assume Acquire, Release, and Yield are threadsafe).
Thank you.
EDIT: It's been running fine for a while now, so I thinkk Wait() is threadsafe.
EDIT2:
I am running into another weird bug. If I run 4 threads (I don't know about numbers larger than four) and use a mutex (in only two of the threads), I get a delay in the bluetooth reception. The code doesn't slow down, but the controls run with a delay.
Last edited by flameout : 10-10-2010 at 01:03.
Reason: Another issue
|