Question about Queueing...

Gary Miyakawa

Active Member
Licensed User
Longtime User
I need to build a small queue system for the data coming from a stream (to get it formatted, separated correctly...

I've looked thru the documentation/tutorials/forums and haven't found much talk about Queues.... I have no problem writing my own but my concern it protecting a few spots where I don't want two processes acting on the same variable, at the same time...

Is there a "locking" mechanism available somewhere ?

Thanks!

Gary M
 

agraham

Expert
Licensed User
Longtime User
My CollectionsExtra library has a LinkedList that can act as a queue or you could build your own using Type, I think Erel has an example somewhere. My Threading library has a Lock object that be used for synchronisation and resource protection. However your reference to "two processes" indicates that you are accessing a common resource from two separate threads, what is the origin of the second thread you are concerned about?
 
Upvote 0

Gary Miyakawa

Active Member
Licensed User
Longtime User
I've got data coming into the program from an AsyncStream which can fire at anytime. I also have buttons that will fire anytime (and can cause some of the data traffic)... The AsyncStream is a non-blocking I/O and because of that, the process that "interprets" the data is running in the "foreground"...

My concern is that foreground and background could compete for the data counter variable and cause an issue.. I've had this problem with Windows programs... and had to code it this way on the iPhone... Just figured that Android/B4A would have similiar issues..

Thanks for the response!

GaryM
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Unless you are using agraham Threading library (or OpenGL), your code always runs in the main thread. It is true that many libraries run tasks in the background.
However when the event is raised it is raised in the main thread. This is also true for AsyncStreams (which uses two additional threads under the hood).

This means that you should not worry about synchronization issues.
 
Upvote 0
Top