full control of the microprocessor。
o To implement tasks that you want to run separately from the main program; you
use threads。
o Each program that is started is a task and has a main thread from which you can start
other threads。
o Threading is not difficult and easily implemented。 What is more difficult is synchroniza
tion between the threads。
o Synchronization is not about the data; but about synchronizing access to code that
modifies data that is shared。 If your data is not shared; you don’t need synchronization。
o In the context of a single application; you will use either the exclusive lock or the Monitor
for synchronization。
o Locking code slows down the code。 You should keep the locks for the shortest time possible。
o To improve throughput; you can take a snapshot of the data。
o Higher…level synchronization abstractions are the reader/writer and producer/consumer
architectures。
…………………………………………………………Page 391……………………………………………………………
C HA P TE R 1 3 ■ L E AR N IN G AB O U T M U L T IT HR E AD IN G 369
o Reader/writer locks are exclusive locks; but they separate code that reads from code
that writes。 To improve code efficiency; reader/writer locks allow multiple readers; but
only a single writer。 Reader/writer locks are effective only if; for the most part; you are
reading data。
o Producer/consumer locks split the task of producing and consuming data into two sepa
rate steps。 The API uses the producer/consumer concept extensively; examples are
Windows。Forms and IAsyncResult。
o Deadlocks occur because timing changes cause your code to not be deterministic。
o Deadlocks can be partially avoided using Monitors; but the most effective way of avoiding
deadlocks is to use the producer/consumer development technique。 This is because the
producer/consumer architecture takes the approach of handing off data; rather than
sharing data。
o Applications that multitask effectively are applications that have been designed using
logic; rather than development techniques where you think up the code as you go along。
Some Things for You to Do
The following is an exercise to help you apply what you learned in this chapter。
1。 Write a general architecture that generates a series using multiple threads。 For the first
series; generate the square of all numbers between 1 and 100。 For the second series;
generate the Fibonacci series。 That is; after two starting values; each number is the sum
of the two preceding numbers。 The first Fibonacci numbers are 0; 1; 1; 2; 3; 5; 8; 13; 21;
34; 55; 89; 144; 233; 377; 610; 987; 1597; 2584; 4181; 6765; 10946; 17711; 28657; 46368;
75025; 121393; 196418; and 317811。 Outline the limits of multithreading when generating
a series。
…………………………………………………………Page 392……………………………………………………………
…………………………………………………………Page 393……………………………………………………………
C H A P T E R 1 4
■ ■ ■
Learning About Relational
Database Data
Literally hundreds of techniques; tips; tricks; and libraries are associated with relational data
bases。 Covering relational databases would take an entire a book; and in fact; many books are
devoted to that subject。 This chapter will cover the basics and give you enough knowledge to
read and write to a database。
The focus of this chapter is to demonstrate accessing relational databases with ADO
and the Visual Studio Dataset Designer。 Since we’ll need a database to work with; you’ll also
learn how to create a database with Visual Basic Express。
A relational database stores data; such as the lottery numbers in Chapter 10’s example。
Building on that lottery…prediction example; in this chapter; you’ll see how to create a database
application that reads and writes the lottery numbers; and associates winners with a particular
lottery drawing。
Understanding Relational Databases
As a beginner developer; one of your greatest challenges will be how to manage relational database
data。 A relational database is an old piece of technology。 The relational model on which it is based
was written in about 1969 (according to the relational model entry at http://en。wikipedia。org/
wiki/Relational_model)。 A relational database is defined as follows (http://en。wikipedia。org/
wiki/Relational_database):
Strictly; a relational database is merely a collection of relations (frequently called
tables)。 Other items are frequently considered part of the database; as they help to organize
and structure the data; in addition to forcing the database to conform to a set of
requirements。
Relational Database Tables
A relational database is a collection of tables。 When you were reading and writing a file in
Chapter 10’s example; you were actually reading and writing a table of lottery numbers; which
looked something like this:
371
…………………………………………………………Page 394……………………………………………………………
372 CH AP T E R 1 4 ■ L E A R N I N G A B OU T R E L A TI O N AL DA TA B AS E D AT A
2000。05。31 5 6 13 23 25 37 43
2000。06。03 7 10 11 18 32 41 5
2000。06。07 15 23 24 28 38 39 45
2000。06。10 1 3 12 23 29 33 27
2000。06。14 2 4 13 19 39 45 26
2000。06。17 3 8 17 19 21 25 35
小说推荐
- oracle从入门到精通(PDF格式)
- -Page 1-Oracle 从入门到精通-Page 2-资源来自网络,仅供学习 Oracle 从入门到精通一、SQL 8
- 最新章:第37章
- C语言游戏编程从入门到精通(PDF格式)
- -Page 1-Page 2-Page 3-Page 4-Page 5-Page 6-Page 7-Page 8-Page 9-Page 10-Page 11-Page 12-Page 13-Page 14
- 最新章:第4章
- Java编程思想第4版[中文版](PDF格式)
- -Page 1-Page 2《Thinking In Java》中文版作者:Bruce Eckel主页:http/BruceEckel.编译:Trans Bot主页:http/memberease~transbot致谢-献给那些直到现在仍在孜孜不倦创造下一代计算机语言的人们!指导您利用万维网的语言进
- 最新章:第295章
- 深入浅出MFC第2版(PDF格式)
- -Page 1-Page 2-山高月小山高月小 水落石出水落石出山高月小山高月小 水落石出水落石出-Page 3-深入淺出MFC(第版 使用Visual C 5.0 MFC 4.2)Dissecting MFC(Second Edition Using Visual C 5.0 MFC 4.2)侯俊
- 最新章:第309章
- VC语言6.0程序设计从入门到精通
- -Page 1-Visual C 6.0 程序设计从入门到精通求是科技 王正军 编著
- 最新章:第136章
- SQL 21日自学通(V3.0)(PDF格式)
- -Page 1-SQL 21 日自学通(V1.0 翻译人 笨猪目录目录 1译者的话 14第一周概貌 16从这里开始 16
- 最新章:第170章
- 2008年青年文摘精编版
- 作者:中国青年出版社“初恋”的惩罚.作者:凡 凡 文章来源《真情》2005年第4期 点击数:6608 更新时间:2005-6-5过了年,我就十八岁了。离高考只剩下四个多月了。这一段,班里的男女生相互间递纸条、写情书、约会等地下活动慢慢的多了起来。我这个“尖子生”也突然感到了不安、慌乱,并且自责。不知
- 最新章:第230章
- JMS简明教程(PDF格式)
- -Page 1-JMS1.1规范中文版卫建军2007‐11‐22-Page 2
- 最新章:第28章
- SQL语言艺术(PDF格式)
- -Page 1-SQLSSQQLL语言艺术内容介绍本书分为12章,每一章包含许多原则或准则,并通过举例的方式对原则进行解释说明。这些例子大多来自于实际案例,对九种SQL经典查询场景以及其性能影响讨论,非常便于实践,为你数据库应用维护人员阅读。资深 SQL 专家 Stéphane Faroult倾力打
- 最新章:第27章