discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Thread Synchronization


From: Eric Blossom
Subject: Re: [Discuss-gnuradio] Thread Synchronization
Date: Wed, 13 May 2009 13:20:27 -0700
User-agent: Mutt/1.5.18 (2008-05-17)

On Wed, May 13, 2009 at 03:33:41PM -0400, Tom Lutz wrote:
> 
> I currently have a thread-safe *cue spock brow* way of re-allocating the
> buffers while the scope is running but it is not as clean as using a mutex
> (although it is faster, I'm sure). Here's how my method works.  Tell me if
> you think it is flawed or a hack-job...
> 
> Two booleans (private member vars of the gr_oscope_guts class) control the
> synchronization of the threads:
>   bool        _update_record_count_internal;
>   bool        _update_record_count_state_internal;
> 
> Thread A (the GUI), inverts the boolean _update_record_count_internal to
> signal the other thread to perform an action (via the
> set_samples_per_output_record function)
> 
> Thread B (the data flow), compares the two booleans inside the
> process_sample function and takes action if they are inequal. It inverts its
> boolean after performing the operation.

This might work on x86 machines, but isn't safe on machines
with weak memory ordering across processors (e.g., PPC, Itanium).
You'd need to introduce architecture specific memory barriers.

Can you put the mutex at a higher level (e.g., in the object that
has the gr_oscope_guts)?

Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]