Because, since all their calls arrive on the same thread, STA components don't require synchronization code to protect them against concurrent access from different threads. Anyone who has ever used a chain saw understand the hazards of being disturbed at the wrong moment. Similarly, an object can cause untold damage if an unruly thread joggles its elbow while the object performs delicate operations on a different thread.
If we put our components not in an STA, but rather in the process's lone MTA or NA, then the object can receive calls from multiple threads at the same time. This means that we have to write our own synchronization code to protect critical operations, essentially erecting a fence around ourselves so no one can bother us while we're making a cut with the chainsaw.
This doesn't sound all that bad, but as we saw in the last issue of ThunderClapit is extremely difficult to get it right for all callers in all cases, essentially impossible in a distributed system.
It takes a lot of time and costs a lot of money to develop non-revenue infrastructural code that A is the same for most distributed operations, so you're re-inventing the Neverwnding Beer - 666 Packs - Free Beer Here Vol.1 (CD) and B doesn't work very well, so your customers aren't happy.
We want to get rid of thread affinity and its resulting bottlenecks, but the price of writing our own synchronization code is extremely high. We'd love it if this problem just went away. This is a generic problem, and we'd really like a generic solution to it.
We'd really like someone to abstract the problem away for us, as has, for example, the Java language. Java requires us to add only a single keyword, "synchronized" to the method definition in our source code like this:. That's fine if you are going to write all of your COM code in Java, but no one is doing that today, Neverwnding Beer - 666 Packs - Free Beer Here Vol.1 (CD). Microsoft and Sun's legal wrangles have stunted the growth of this language in the Windows environment more surely than mere hostility from Microsoft ever could.
No one really wants to use a language that some idiot lawyer might declare illegal on some future date, no doubt the day before you were to ship your product.
Even the thought of an civilized audit that might uncover the pornographic movies they've been downloading on the company T1 line fills them with dread. Rumors in the trade press speculate that Microsoft might drop Java support, possibly replacing it with a language called "Cool". Plus Java components execute slowly due to the additional layer of abstraction provided by the JVM. Not many developers will make this switch any time soon.
What we'd really like is some way to implement that same idea for any COM component, not just one written in Java. We'd like synchronization code, similar to what the JVM uses when it sees that keyword, to become part of the operating system, available on a binary basis. We want Microsoft to add a generic synchronization service to the operating system. One such piece is synchronization. The others, as discussed in my new book, are security, transactions, queued components, events, in-memory database, and load balancing.
If you think of a standard COM proxy and a stub, but with a lot more brains, you'll have about the right mental model. This program will OK, should work on the Beta 3 version or later of any flavor Professional, Server, etc. You can click here to download the code. Expand the snap-in's left-hand tree until you see the "Applications" folder. Left-click on it to select it, then right-click on it and choose "New -- Application". Follow the Wizard steps to create a new empty application, accepting the Wizard's default options.
You should see your new application appear in the tree. We need an application to hold our component, but it is not otherwise interesting in this example. Expand your new application until you see its "Components" folder. Left-click on this to select it, then right-click on it and choose "New -- Component". Follow the Wizard's instructions to add a new component not one that is already registered. Use the file selection dialog box to select the file containing the sample component, "RTSynchDemo.
Your Component Services snap-in will look something like this:. Now right-click on your new component, select "Properties", then select the "Concurrency" tab from the property sheet. Your property page will look something like this:.
The "Required" button should already be selected; if not, select it and click OK. There's so much new administrative information that they couldn't fit it into the existing registry. Reading and writing the data in the catalog is not restricted to human users of the snap-in; system-provided objects make it accessible to programs as well.
Now that your component is properly installed and configured, run your client app, called "mfcclient. It will look like this:. Click the "Create" button. The object pointer is stored as a global variable in the client app. It just uses COM the way it always has. The creation process may take longer than you are used to because launching the app requires more thinking on the part of the operating system, as shown below.
The SCM in Windows has gotten smarter. It looks at the application to which the component belongs, sees that it is configured to run in a spearate address space, and launches the utility program "dllhost. It then creates a new object using the same class factory as always.
It then checks the component's administrative properties that you made in the catalog, such as whether or not it requires synchronization. These policy objects are positioned between the client and the channel, and between the channel and the stub, as shown below:. When a call goes from the proxy to the channel, the client's policy objects are executed. When a call goes from the channel to the stub, the server's policy objects are executed.
In the synchronization case shown here, a server policy object would check to see if the incoming call was part of the same activitythe same logical call stack.
If not, it would wait on a mutex that the policy created when it was first set up. If the mutex was unowned, the call would proceed directly to the object. If not, if some other thread was already in a call to Neverwnding Beer - 666 Packs - Free Beer Here Vol.1 (CD) object, it would block. When the call returns from the stub, the policy object would release the mutex. Note: Real geeks always ask at this point where the spec for a policy object can be found and how can they write one to implement their own interception logic.
I think Microsoft wants to reserve the right to make changes to the policy architecture based on what they learn from version 1. To demonstrate this functionality, click the "Call from Thread A" button in your client app.
Internally the client app will pass the request from the UI thread to a worker thread that it keeps around for this purpose. The worker thread will make the call to the object.
You will see a dialog box, saying "Hello". Do not dismiss it; leave it up so the COM call doesn't return. Now click the "Call from Thread B". The UI posts the message to a different worker thread, which makes the COM call as the first one did. However, you don't see a second message box. That's because thread B's call is blocked at the policy object. When you click OK to get rid of the first message box, you will immediately see the second one. Neither client nor server wrote any synchronization code.
Note: The word "inherit" strikes a deep emotional chord in object oriented programmers. I am using it here in its most generic sense, of something valuable dumped in your lap in return for no effort on your part, which you don't deserve and will probably squander. I'm not using it in the rigorous OO sense of the word. Either click "Release" or close the client app. Now you Neverwnding Beer - 666 Packs - Free Beer Here Vol.1 (CD) to shut down the server.
It has a system-configured timeout interval that defaults to 3 minutes. Either wait this long, or right-click on your application in the snap-in and choose "Shut Down" from the context menu.
Now bring up the component's property page as before. You probably noticed that some of the choices in the picture above were grayed out. Now go back to the "Concurrency" tab and click the radio button that says "Not Supported". Click OK, Neverwnding Beer - 666 Packs - Free Beer Here Vol.1 (CD) run the test again. Again, we didn't write any code to make it happen. Since this is the synchronization service that everyone will use, Microsoft could afford to spend a lot of time and money on getting it just right or just how they think it ought to be, which isn't necessarily the same thing.
It's a better service than you could afford to write yourself, because they have many, MANY more units over which to amortize the cost. I realize that this is just a skim of the surface, probably raising as many questions as it answers. That's by design. If you want the rest of the answers, the next section of this newsletter will tell you where to buy them. Think of this article as a free sample of cigarettes. Good luck with it. Platt, President of Rolling Thunder Computing.
It's a different approach than my other books, more of a conceptual overview than a wealth of cut-and-paste code. But - on the other hand - no song did turn my hearing 'system' on. Predictable European Hard Rock music - glad to see it's set 'away' enough from the Frontiers standards we've been fed up with lately - that will apply only to diehard 'melodic' hard rockin' fans.
This site uses Akismet to reduce spam. Learn how your comment data is processed. If anyone has these albums, please share with us, we will be very grateful. Melodic Rock AOR. Surveillance — Angelstation Man — Man Remaster Leave a Reply Cancel reply. Hot CDs Wish List. Enter your email address: Delivered by FeedBurner. Top Year Best Mounth Wanted.
50 Ab 009 - Soerba - Mangiare Sano (CD), Nunya* - Use Me (Vinyl), Inside White - Various - Sunnyside Twenty-Fifth Anniversary Volume 1 (CD), Its My Pleasure (021 Radio Edit) - My Friend Sam, Viola Wills - Its My Pleasure (Cassette), Carrickfergus - Bryan Ferry + Roxy Music - The Platinum Collection (CD), Blitzkrieg Bop - Ramones - Ramones (Vinyl, LP, Album), Landó - Lucho Quequezana - Kuntur (CD, Album), Intro - Roc Marciano* - The Pimpire Strikes Back (CDr)