Embodiment
In the following detailed description, to the part of book as an illustration and specific implementations is described by way of example or embodiment and the accompanying drawing that illustrates carries out reference.In some accompanying drawings, similar Reference numeral is represented similar assembly, entity and configuration.Other embodiment can be made up, can use to these embodiments and constructive variations can be under the situation that does not deviate from the spirit and scope of the present invention, carried out.Therefore, below describe in detail and should not treat, and scope of the present invention is by appended claims and equivalents definition thereof with the restriction theory.
Fig. 1 illustrates the suitable computing environment that is used to realize concurrent domain.Though not necessarily, embodiments of the present invention will be described in the general context of the computer executable instructions of being carried out by personal computer.Usually, programming operation is carried out particular task or is realized particular abstract data types.
System 100 comprises processing unit 102, system storage 104 and will comprise that the various system components of system storage 104 are coupled to the system bus 106 of processing unit 102.System bus 106 can be to comprise in the some types of bus structures of memory bus, peripheral bus and local bus of using in the various bus architectures any any.System storage comprises ROM (read-only memory) (ROM) 108 and random-access memory (ram) 110.The basic input/output 112 (BIOS) that comprises the basic routine of transinformation between the element of help in computer system 100 is stored among the ROM108.
Computer system 100 also comprises hard disk drive 112 from disk read-write, from the disc driver 114 of moveable magnetic disc 116 read-writes with from CD drive 118 such as removable CD 119 read-writes of CD ROM, DVD or other optical medium.Hard disk drive 112, disc driver 114 and CD drive 118 can be connected to system bus 106 by hard disk drive interface 120, disk drive interface 122 and CD drive interface 124 respectively.Driver and associated computer-readable media thereof provide the non-volatile memories of computer-readable instruction, data structure, program and other data for computer system 100.
Though example context as herein described is used hard disk 112, moveable magnetic disc 116 and removable CD 119, the computer-readable medium that can store other type of data also can be used for this example system 100.The example that can be used for these other type computer computer-readable recording mediums of exemplary operations environment comprises tape cassete, flash card, digital video disc, Bernoulli magnetic tape cassette, random-access memory (ram) and ROM (read-only memory) (ROM).Many program modules can be stored on hard disk 112, disk 116, CD 119, ROM 108 or the RAM 110, and these program modules comprise storage system 126, application program 128, other program module 130 and routine data 132.
The user can by such as the input equipment of keyboard 134, mouse 136 or other pointing device to computer system 100 input commands or information.The example of other input equipment comprises toolbar, menu, touch-screen, microphone, operating rod, game mat, pen, satellite dish and scanner.These and other input equipment is connected to processing unit 102 by the serial port interface 140 that is coupled with system bus 106 usually.Yet these input equipments also can connect by other interface such as parallel port, game port or USB (universal serial bus) (USB).The display device of LCD display 142 or other type also can be connected to system bus 106 via the interface such as video adapter 144.Except display 142, computer system can comprise other peripheral output device (not shown) usually, such as loudspeaker and printer.
Computer system 100 can be connected with the logic of one or more remote computers such as remote computer 146 and operate in networked environment using.Remote computer 146 can be computer system, server, router, network PC, peer device or other common network node, and generally includes above a plurality of or whole in the element that computer system 100 describes of being relevant to.Network connects and comprises Local Area Network 148 and wide area network (WAN) 150.This networked environment is very common in office, enterprises computer network, Intranet and the Internet.
When using in the lan network environment, computer system 100 can be connected to LAN (Local Area Network) 148 by network interface or adapter 152.When using in the WAN network environment, computer system 100 generally includes and be used for the modulator-demodular unit 154 or other device that establish a communications link on the wide area network 150 such as the Internet.Modulator-demodular unit 154 that can be internal or external is connected to system bus 106 via serial port interface 140.In networked environment, the program module that is relevant to the description of computer system 100 or its part can be stored in the remote memory storage device.Should be appreciated that, shown in network to connect be example, and can use other device of between computing machine, setting up communication linkage.
Embodiment described herein can be embodied as the logical operation in the computing system.Logical operation can be embodied as computer realization sequence of steps or the program module of (1) on computer system, moving; And (2) interconnect logic or hardware module of in computing system, moving.This realization is the selection of depending on the performance requirement of concrete computing system.Therefore, the logical operation of formation each embodiment described herein is meant operation, step or task.These operations, step and task can realize in software, firmware, special digital logic and combination in any thereof and not deviate from the spirit and scope of the present invention of setting forth in the appended claims.This software, firmware or similar sequence of computer instructions can be encoded and be stored on the computer-readable recording medium, and also can be coded in the carrier signal of transmitting between the computing equipment.
As above briefly describe, embodiment of the present invention relates to each assembly with software application and is divided into and is used in the discrete territory providing in the assembly subregion synchronously and method, system and computer product that thread is isolated and be used for providing improved concurrent operations between the assembly subregion.Fig. 2 illustrates the example system that is configured according to an embodiment of the present invention in order to a plurality of objects of concurrent execution.Example system 200 comprises concurrent domain 201, this concurrent domain be all on single thread 202, carry out and not with the directly set (or subregion) of (for example or asynchronous) one or more single-threaded object 203 of communicating by letter of external object 210.Internal thread 202 is carried out object 203 according to the logic of being utilized by concurrent domain 201.Internal thread 202 is the single-threaded object 203 in the execution concurrence territory 201 only.Internal thread 202 is not carried out any external object 210.
According to an embodiment, same thread need be always as internal thread 202 in the whole life cycle of concurrent domain 201.On the contrary, when not having object to carry out on internal thread 202, the thread that serves as internal thread 202 can return the thread pool (not shown).In case need thread once more, new thread can be taken out from thread pool to be used as internal thread 202.According to another embodiment, one of single-threaded 203 have thread affinity, represent that this single-threaded object 203 need carry out on same thread.In the present embodiment, same thread is used as internal thread 202 in the whole life cycle of concurrent domain 201.According to an embodiment, also can from thread pool, locate and incite somebody to action in this article secondary thread 204 in greater detail.
Still with reference to Fig. 2, system 200 also comprises at least one secondary thread 204 and at least one external object 210.The embodiment of external object 210 is included in any object of carrying out on one or more secondary thread 204.Secondary thread 204 is included in any thread of carrying out in the affiliate application except that internal thread 202.As mentioned above, example concurrent domain 201 as shown in Figure 2 comprises internal thread 202 and a plurality of single-threaded object 203.Only use internal thread 202 to carry out these single-threaded object 203.
Object 203 in the concurrent domain 201 is separated from secondary thread 204 and external object 210 in the program.Any single-threaded object 203 that secondary thread 204 does not comprise in the execution concurrence territory 201.Each external object 210 is configured to carry out on secondary thread 204 one or more.Single-threaded object 203 asynchronous communications in external object 210 and the concurrent domain 201.Communication is included in Data transmission between the object or by another object the method for an object (for example, or task) is called.
The asynchronous communication that strides across concurrent domain 201 borders realizes by using border object 207.Each concurrent domain 201 is all related with one or more border object 207.These border objects 207 can be regarded as surrounding the barrier film (membrane) or the gated wall (gated wall) of concurrent domain 201.The example of border object 207 is included between the concurrent domain 201 or realizes the data connector and the object of custom protocols between concurrent domain 201 and external object 210.
Single-threaded object 203 in the concurrent domain 201 is used one or more border objects 207 and external object 210 asynchronous communications.Single-threaded object 203 uses internal thread 202 to communicate by letter with border object 207.Border object 207 uses one or more secondary thread 204 to communicate by letter with external object 210 subsequently.The border of taking this border object 207 leap concurrent domains 201 is transmitted information and is called.According to another embodiment, a border object 207 was using secondary thread 204 to communicate by letter with another border object 207 before external object 210 transmission information.
Border object 207 is as the internal thread 202 of concurrent domain 201 and the interface between each secondary thread 204.According to an embodiment, border object 207 uses secondary thread 204 to receive importing communication into and this communication is filled into suitable internal object 203 from external object 210.Filter method will be described in this article in more detail.According to another embodiment, border object 207 use internal thread 202 receive spreading out of communication and using secondary thread 204 with the extremely suitable external object 210 of this communications from internal object 203.According to an embodiment, border object can call external object on internal thread, but so the border object of operation is restricted.That is, allow border object to call external object and must not can cause thus that postpone or deadlock indefinite duration.Another restriction prevents that external object from quoting internal object, thereby prevents that the concurrent domain under the externally object control from directly reentrying.
The thread of carrying out thereon when first object enters second object synchronous communication takes place when carrying out second object method.External object 210 is not carried out synchronous communication with concurrent domain 201 interior single-threaded object 203.Therefore, the single-threaded object 203 in the concurrent domain 201 is not directly called or entered to the secondary thread of execution external object 210.
Fig. 3 illustrates another example system 300 of concurrent domain wherein 301 and external object 310 interfaces.An example of asynchronous communication externally illustrates between object 310 and the internal object 303.Concurrent domain 301 comprises internal thread 302, is configured to the single-threaded object 303 and the border object 307 that is used for communicating by letter with external object 310 of execution on internal thread 302.Another embodiment of native system 300 comprises a plurality of border objects 307 and a plurality of single-threaded object 303.
With reference to another embodiment, external object 310 comprises be configured to the multithreading object 305 carried out on two or more secondary thread.A part of 305A of multithreading object 305 is shown in that a secondary thread 304A go up to carry out and another part 305B of multithreading object 305 is shown in another secondary thread 304B and goes up and carry out.According to another embodiment, the single-threaded object (not shown) that external object 310 comprises a plurality of multithreading objects 305 or is configured to carry out on a secondary thread 304.
Concurrent domain 301 maintenance work formations 308 in the system 300.Work queue 308 is multielement data structures of charging to (for example, inserting) task (for example method, Data Update and other executing method of inside, single-threaded object 303 calls) thereon or therefrom removing task.According to an embodiment, only can task be removed from work queue 308 to charge to identical order with task; Promptly follow the restriction of first in first out.According to another embodiment, can be to the Task Distribution right of priority of charging to formation, and remove each task according to its right of priority.
Import communication into and charge to work queue 308 by border object 307.These communications of having charged to form jobs 311, and these jobs are to be used to carry out inside, single-threaded object 303 or the request (for example, calling) of the task of the border object 307 that is associated with concurrent domain 301.The request that forms job 311 can be communicated to this border object 307 by external object 310 or by another border object 307.For example, in Fig. 3, the multithreading object 305 request border objects 307 of external object 310 are executed the task, shown in arrow 320.Border object 307 will comprise that the job 311 of this task is logged into the end of 308 work queues, shown in arrow 325.According to another embodiment, a plurality of border objects 307 are associated with concurrent domain 301, and one or more in these border objects 307 can charge to job 311 in work queue 308.According to another embodiment, inner, single-threaded object 303 request border objects 307 are charged to job 311 task executions is deferred to the later moment in work queue 308.
According to an embodiment, in order to guarantee that when preparing to charge to new task in work queue 308 resource is certain, border object 307 is checked work queue 308 and is determined whether that the job 311 of any queuing comprises inter-related task.If there is inter-related task, then border object 307 is optionally packed new task as subtask and the inter-related task of before having joined the team, rather than new task is charged to as a whole new job 311.
Still with reference to Fig. 3, according to an embodiment, concurrent domain 301 comprises the scheduler 309 that is used to handle to single-threaded object 303 despatching work projects 311 from work queue 308.Scheduler 309 uses internal thread 302 to remove job 311 from work queue 308 and dispatches each task 311 for carrying out in internal thread 302.Scheduler 309 calls being included in the job 311 of task.For example in Fig. 3, scheduler 309 is despatching work project 311 from work queue 308, shown in arrow 330.Then, job is carried out on internal thread 302, shown in arrow 335.
According to an embodiment, charge to job 311 to work queue 308 and can't force scheduler 309 to make action.On the contrary, the execution of job 311 is delayed to the time point by the top layer circle logic appointment of concurrent domain 301.In case job is credited to work queue 308, then internal thread 302 is carried out institute's tasks requested in concurrent domain 301 next suitable circulation of being determined by scheduler 309.Therefore, when external object 310 and uncertain job 311 are removed, and therefore when the task of also uncertain inside, single-threaded object 303 is called and carries out.When external object 310 same uncertain border objects 307 execute the task on the internal thread 302 of concurrent domain 301.
In case task is scheduled and finishes, then spread out of the result and be delivered to border object 307 as callback.Border object 307 subsequently with this callback communications to external object 310, be exactly that this external object 310 is charged to the job 311 of calling the task of realizing this result at first.The example of callback comprises mark that data, indication task finish, method callback etc.
Fig. 4 has described the asynchronous communication between inside, single-threaded object and the external object.According to the embodiment of the present invention, show the communication chain 400 that takes place in the asynchronous communication process between the object 401 and internal single-threaded object 409 externally.External object 401 at first communicates by letter 402 with border object 403.This communication 402 have usually call or task that request call is related with the concurrent domain (not shown) in one or more forms.Though institute's tasks requested is actually the task of single-threaded object 409,401 of external object are related with concurrent domain or border object 403 with this task.
Then, border object 403 communicates by letter 404 with work queue 405.This communication 404 generally includes charges to work queue 405 with the job (not shown).Work queue 405 communicates by letter 406 with scheduler 407 subsequently.This communication 406 generally includes each job of charging in the scheduler 407 continuous despatching work formations 405.At last, scheduler 407 communicates by letter 408 with the invoked internal single-threaded object 409 of its task.This communication 408 generally includes the task of calling internal single-threaded object 409.In another embodiment, external object 401 is communicated by letter with another border object (not shown) of concurrent domain.
As the above puzzlement of avoiding the reentry problem described in background technology one joint with reference to the described asynchronous communication protection internal single-threaded object of striding the concurrent domain border of Fig. 2-4.Such as will be appreciated, when the object under the top layer logic control of concurrent domain (for example, internal single-threaded object or border object) direct internal thread is reentried same another object under this top layer logic control, can cause the reentry of internal control.When not being object (for example, external object) direct internal thread under the logic control of concurrent domain item layer when reentrying object under this top layer logic control, can cause external control to reentry.In reentrying own or same concurrent domain, internal object during another object, can cause inside to cause reentrying.When the time effects that caused by external object is reentried, thereby when removing control by the logic from be included in the concurrent domain internal object jointly of reentrying effectively, can cause the outside to cause reentrying.The result is exactly uncertain the reentry.
Again with reference to Fig. 3, the asynchronous communication protection internal single-threaded object 303 that only allows to stride concurrent domain 301 is avoided the external control reentry.For example, if the execution of internal single-threaded object 303 comprises the task of calling external object 310, then internal thread 302 will enter will calling in the lump of the border object 307 that is associated with concurrent domain 301 task that the task of external object 310 is responsible for will be carried out in request.Internal thread 302 can turn back to the task of carrying out internal single-threaded object 303 subsequently or turn back to the modulated degree job 311 of execution from work queue 308.It because can not leaving concurrent domain 301, internal thread 302 does not enter external object 310, so can not fall under the control of external object 310.
In addition, if, then do not allow internal thread 302 reentry concurrent domains 301 if the task and this task executions that allow internal thread 302 to carry out external object 310 comprise another task of calling internal single-threaded object 303.On the contrary, internal thread 302 border object 307 that can enter concurrent domain 301 calls the task of being responsible for charging to job 311.Perhaps, as mentioned above, under some restriction, border object can call external object and come calling task on internal thread.After calling this task, internal thread 302 turn back to the task of carrying out external object 310 and turn back to subsequently carry out internal single-threaded object 303 first, ancestral task.In other words, internal thread 302 can not carried out by calling up to first task of 310 pairs second tasks of external object and finish and up to finishing aforesaid operations by scheduler 309 guiding of concurrent domain 301.
Referring now to Fig. 5 and 6,, come embodiments of the present invention are described at exemplary external object with data source.Fig. 5 illustrates the system 500 that comprises concurrent domain 501 and data source 512, and Fig. 6 shows the operational flowchart 600 of the interface between the secondary thread 504 of the internal thread 502 of describing concurrent domain 501 and data source 512.In one embodiment, secondary thread 504 comprises a plurality of secondary thread 504.Concurrent domain 501 comprises single-threaded object 503 and scheduler 509, and is associated with border object 507.Concurrent domain 501 is safeguarded the work queue 508 of the hang-up task carried out of indicating on the internal thread 502 of concurrent domain 501.In one embodiment, data source 512 is databases.In another embodiment, data source 512 is networks.
The execution route of internal thread 502 and secondary thread 504 is shown in two accompanying drawings.In Fig. 5, dotted arrow has been described the task of carrying out and has been carried out on internal thread 502, and the task that solid arrow has then been described to take place on one or more in secondary thread 504 is carried out.The Reference numeral that refers to dotted line and solid arrow is corresponding to operation or the task carried out at Fig. 6, and wherein Fig. 6 illustrates each task of arranging along the thread of carrying out thereon.
Still with reference to Fig. 5 and 6, this method begins at beginning frame 601, and proceeds to operation 602, and wherein single-threaded object 503 request border objects 507 call being associated with data source 512 of task.This request is carried out on the internal thread 502 of concurrent domain.In operation 603, scheduler 509 is according to work queue 508 orders and dispatch each job 511.According to an embodiment, charge to internal thread 502 each job 511 of scheduling that use in order of work queue 508 with job 511.For example, suppose not have new job 511 to be added to therebetween, then scheduler 509 is by job 1 beginning sequence and by job 7 end sequence.Can after job 7, add any new job 511.According to another embodiment, according to the priority valve despatching work project 511 of distributing.
Method 602 is also led to and operation 602 methods that are performed simultaneously 611.In method 611, border object 507 calls being associated with data source 512 of task.This is invoked on one of secondary thread 504 and carries out.Afterwards, this method proceeds to operation 612, wherein carries out the task of data source 512 in secondary thread 504 on one or more.Next, operation 613 comprises that database 512 sends back border object 507 with execution result as callback.This result's one or more the going up that is transmitted in secondary thread 504 taken place.Then, in operation 614, border object 507 is charged to work queue 508 with callback as job 511.This one or more going up that is logged in secondary thread 504 is carried out.
From operating 614, this method proceeds to operation 604.Operation 603 also can be led to operation 604.When the scheduler 509 of the job 511 in the order execution work formation 508 in operation 603 arrived the callback job 511 of being added by border object 507 in operation 614, operation 604 took place.Scheduler 509 uses internal thread 502 to arrive callback.In case callback is scheduled, then scheduler 509 continues each job 511 in operation 605 sequential scheduling work queues 508.
Referring now to Fig. 7 and 8, embodiments of the present invention are described at the exemplary external object that comprises second concurrent domain.Fig. 7 shows the system 700 that comprises first concurrent domain 701 and second concurrent domain 721 respectively, and Fig. 8 shows the operational flowchart 800 of first concurrent domain 701 and second concurrent domain, 721 interfaces therein.Each concurrent domain 701,721 comprises internal thread 702,722, single-threaded object 703,723 and scheduler 709,729 respectively.Each concurrent domain 701,721 is associated with border object 707,727 respectively and safeguards the work queue 708,728 of the hang-up job 711,731 carried out of indicating respectively on internal thread 702,722.In Fig. 7, first group of dotted arrow is illustrated in taking place on the internal thread 702 of task and carries out, one group of solid arrow is illustrated in the one or more of secondary thread 704 and goes up the tasks execution that takes place, and second group of dotted arrow is illustrated in the task execution that takes place on second internal thread 722.These dotted lines and solid arrow show the execution that relates to the various operations of communicating by letter between first concurrent domain 701 and second concurrent domain 721.The Reference numeral that refers to these arrows is corresponding with operation or the task carried out at Fig. 8.
Still with reference to Fig. 7 and 8, this method is in 801 beginnings of beginning frame and proceed to operation 802 and 822.Operation 822 comprises uses internal thread 722 to come the scheduler 729 of second concurrent domain 721 of each job 731 in the sequential scheduling work queue 728.Operation 802 is carried out simultaneously with operation 822.At the single-threaded object 703 request border objects 707 of operation 802, the first concurrent domains 701 from one of the object of second concurrent domain 721 calling task.In one embodiment, institute's tasks requested is the task of one of the single-threaded object 723 of second concurrent domain 721.In another embodiment, institute's tasks requested is the task of one of border object 727 of being associated with second concurrent domain 721.
From operating 802, this method proceeds to two operations 803 and 812.Each job 711 in the scheduler 709 sequential scheduling work queues 708 of operation 803, the first concurrent domains 701.Border object 707 in operation 812, the first concurrent domains 701 uses the one or more of secondary thread 704 to communicate by letter with the border object 727 of second concurrent domain 721.Communication comprises the request of degree of exchanging task.Then, at operation 813, the second border objects 727 institute's tasks requested is charged to work queue 728 as job 731.This charges to one or more execution of use secondary thread 704.
Operation 823 is all led in operation 813 and operation 822.In operation 823, scheduler 729 arrives and dispatches the job 731 that comprises institute's tasks requested.This scheduling is carried out on the internal thread 722 of second concurrent domain 721.In operation 824, carry out this task subsequently as callback to single-threaded object 703 in first concurrent domain 701.In this, this method separate once more and proceed to the operation 825 and 814.In operation 825, each job 731 that scheduler 729 continues in the sequential scheduling work queue 728.
Operation 814 takes place simultaneously with operation 825.In operation 814, the border object 727 of second concurrent domain 721 uses one or more secondary thread 704 to ask the border object 707 of first concurrent domain 701 that callback is charged to work queue 708 as job 711.Afterwards, in operation 815, border object 707 is charged to work queue 708 with this callback.This one or more going up that is logged in secondary thread 704 is carried out.
When the scheduler 709 of first concurrent domain 701 arrives the callback that is logged in the work queue 708, operate 804.Scheduler 709 uses the internal thread 702 of first concurrent domain 701 to dispatch this callback.This callback is carried out in operation 805.Afterwards, this method proceeds to operation 806, and scheduler 709 continuation are therein dispatched each job 711 in an orderly manner according to the order of work queue 708.This method finishes 806.
Another example (not shown) of system comprise interface each other and with three or above concurrent domain of other external object interface.This system is basically according to coming work with identical operations described herein.Each concurrent domain in this system comprises internal thread, one or more single-threaded object and scheduler.But each concurrent domain can with at least one border object to related and maintenance work formation.All communications of striding the concurrent domain border all are asynchronous (for example, border object, work queue and the scheduler by response filter).
Aforesaid each embodiment only provides in illustrational mode, and should not be construed restriction the present invention.Those skilled in the art are easy to recognize and can make various changes and variation to the present invention, and example embodiment that does not illustrate and describe according to this paper and application and do not deviate from true spirit of the present invention and the scope of in appended claims, setting forth.