<< 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

who was the first nanotechnologist
Lizzy Reply
k
Veysel
technologist's thinker father is Richard Feynman but the literature first user scientist Nario Tagunichi.
Veysel
Norio Taniguchi
puvananathan
Interesting
Andr
I need help
Richard
anyone have book of Abdel Salam Hamdy Makhlouf book in pdf Fundamentals of Nanoparticles: Classifications, Synthesis
Naeem Reply
what happen with The nano material on The deep space.?
pedro Reply
It could change the whole space science.
puvananathan
the characteristics of nano materials can be studied by solving which equation?
sibaram Reply
plz answer fast
sibaram
synthesis of nano materials by chemical reaction taking place in aqueous solvents under high temperature and pressure is call?
sibaram
hydrothermal synthesis
ISHFAQ
how can chip be made from sand
Eke Reply
is this allso about nanoscale material
Almas
are nano particles real
Missy Reply
yeah
Joseph
Hello, if I study Physics teacher in bachelor, can I study Nanotechnology in master?
Lale Reply
no can't
Lohitha
where is the latest information on a no technology how can I find it
William
currently
William
where we get a research paper on Nano chemistry....?
Maira Reply
nanopartical of organic/inorganic / physical chemistry , pdf / thesis / review
Ali
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
hey
Giriraj
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
revolt
da
Application of nanotechnology in medicine
has a lot of application modern world
Kamaluddeen
yes
narayan
what is variations in raman spectra for nanomaterials
Jyoti Reply
ya I also want to know the raman spectra
Bhagvanji
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
STM - Scanning Tunneling Microscope.
puvananathan
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




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