Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Sticky Broadcasts and Concurrency
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Soonil Nagarkar  
View profile  
 More options Oct 13 2008, 6:35 pm
From: Soonil Nagarkar <soon...@gmail.com>
Date: Mon, 13 Oct 2008 15:35:53 -0700 (PDT)
Local: Mon, Oct 13 2008 6:35 pm
Subject: Sticky Broadcasts and Concurrency
I have a component that uses sticky broadcasts to send out state
information about itself along the lines of enabled/disabled. By using
sticky broadcasts, anybody that needs to check the state of the
component (which can be changed at any time by other threads) can stay
up to date rather than using a polling mechanism which doesn't
guarantee any 'up-to-date-ness'.

However, my understanding of the sticky broadcast documentation is
that sticky broadcast intents stay around forever unless removed and
never replace each other. Since I don't want some huge list of
previous intents gumming up the system, and since other components
only need the last sticky broadcast, not the whole list, to determine
what the current component state is, I use removeStickyBroadcast() to
always remove the last intent. As far as I can see however, this leads
to concurrency problems. See the following code...

Ex 1.

if(last_broadcast != null)
        context.removeStickyBroadcast(last_broadcast);

//it is possible for a thread to interleave its own call to
registerReceiver() right here, and not get any
//information on the previous component state

last_broadcast = new Intent(...);
context.sendStickyBroadcast(last_broadcast);

Ex 2.

Intent new_broadcast = new Intent(...);
context.sendStickyBroadcast(last_broadcast);

//it is possible for a thread to interleave its own call to
registerReceiver() right here, and receive two sticky
//broadcast intents instead of one. a better, but not ideal solution.

if(last_broadcast != null)
        context.removeStickyBroadcast(last_broadcast);
last_broadcast = new_broadcast;

Neither of these two scenarios solves the problem entirely, and I
can't imagine any way to make this synchronous with respect to other
registerReceiver() calls.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.