<< Chapter < Page Chapter >> Page >
This module describes the very basics of Micorsoft Visual Basic queues and also the AutoResetEvent event.

Introduction

This module describes the basics of Visual Basic queues and also describes the AutoResetEvent event.

Reading

Queues

Queues in Visual Basic (VB) are very simple to work with and very flexible. Defining a queue object is done with the following command:

Dim myQ As New Queue

This creates a single queue object named myQ . The main methods described in this module are:

myQ.Enqueue() myQ.Dequeue()

The Enqueue method puts items on the queue and the Dequeue method takes items off the queue. With these two methods the queue works as a first-in-first-out (FIFO) type of queue. A property of the queue object that is very useful is the count property:

myQ.count

This returns the number of items in the queue.

VB queues are not thread safe. This means that the operating system does not prevent multiple threads from modifying a queue at the same time. This can cause problems if you have multiple threads reading and writing to the same queue.

If you have multiple threads removing items from a queue you can run into problems. If a thread accesses the count property and it says there is an object on the queue and then the thread tries to access that element, another thread may remove it from the queue before the first thread has a chance to access it. If there is only one thread that removes items from a queue you will not have this problem.

To assure that a queue is thread safe you should use the Synchronized method of the queue. This method returns a wrapper for the queue that assures that the queue is thread safe. It does not fix the problem where two threads are taking items off the queue at the same time though. To use the Synchronized method first make a queue object and then make an object with the Synchronized method.

Dim myQ As New Queue Dim mySyncdQ As Queue = Queue.Synchronized(myQ)

The queue mySyncdQ is a thread safe queue.

To synchronize threads that communicate using a queue, there is a need for the writing thread to inform the reading thread that there is something available on the queue. This signaling prevents the reading thread from wasting time checking to see if anything is available on the queue. The reading thread will simply wait to be signaled that something is on the queue and then it will access the queue. To do this you can use an AutoResetEvent event.

From the MSDN help files: " AutoResetEvent allows threads to communicate with each other by signaling. Typically, this communication concerns a resource to which threads need exclusive access. A thread waits for a signal by calling WaitOne on the AutoResetEvent . If the AutoResetEvent is in the non-signaled state, the thread blocks, waiting for the thread that currently controls the resource to signal that the resource is available by calling Set . Calling Set signals AutoResetEvent to release a waiting thread. AutoResetEvent remains signaled until a single waiting thread is released, and then automatically returns to the non-signaled state. If no threads are waiting, the state remains signaled indefinitely. If a thread calls WaitOne while the AutoResetEvent is in the signaled state, the thread does not block. The AutoResetEvent releases the thread immediately and returns to the non-signaled state. There is no guarantee that every call to the Set method will release a thread. If two calls are too close together, so that the second call occurs before a thread has been released, only one thread is released. It is as if the second call did not happen. Also, if Set is called when there are no threads waiting and the AutoResetEvent is already signaled, the call has no effect."

Questions & Answers

where we get a research paper on Nano chemistry....?
Maira Reply
what are the products of Nano chemistry?
Maira Reply
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
Google
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
revolt
da
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Ti dsp/bios lab. OpenStax CNX. Sep 03, 2013 Download for free at http://cnx.org/content/col11265/1.8
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Ti dsp/bios lab' conversation and receive update notifications?

Ask