友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!阅读过程发现任何错误请告诉我们,谢谢!! 报告错误
狗狗书籍 返回本书目录 我的书架 我的书签 TXT全本下载 进入书吧 加入书签

VB2008从入门到精通(PDF格式英文版)-第175章

按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!




                  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 



            
返回目录 上一页 下一页 回到顶部 0 0
未阅读完?加入书签已便下次继续阅读!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!