Single Threaded Apartment 정리되지 않은 기술

Single Thread Apartment(STA) 는 Visual BASIC 에서 ActiveX DLL을 개발하거나 AX EXE 를 개발하면 default 로 갖게 되는Thread Model 입니다. 또한, Multiple Thread Apartment(MTA)로 구성 될 수 없습니다. 오히려 MTA 는 이해하기가 쉬운데, STA가 좀처럼 이해 하기가 쉽지 않은 모델이라 몇 가지 정리해볼까 합니다.
 

Thread

Thread 는 실행 최소 단위입니다. Application 관점에서 main () 함수에서 나열된 구문을 모두 해석하여 시스템에서 수행이 되면, 그냥 하나의 Thread가 수행된 겁니다. 만일, 나열된 구문 중에Thread를Fork 하는CreateThread API가 호출된다면, 기존의Thread는 그냥 흘러가고 동시에 또 다른Thread 가 만들어져서 걔도 걔 나름대로 흘러가게 됩니다.

Apartment

Thread가 실행되다가 필요에 의해서 개발된AX(또는COM)에서 제공되는 Object를 호출하고 수행할 필요가 있을 겁니다. 이 때 이와 같은Object 는 임의의Apartment 에 위치하고 그 위치를Thread가 접근하게 됩니다. 이Apartment 는 일종의 보호 장벽일 수 있고, 뭔가 끼리끼리 모이기 위한 공간이라고 생각할 수도 있을 겁니다. 하여튼, CoInitialize()/CoInitializeEx() 함수는Apartment 를 만들고, CoUninitialize() 는 해당Apartment 를 해제합니다. 그 안에서 COM 이 존재합니다. VB COM 은 Single Thread Apartment 라는 곳에 위치합니다. 해당Apartment 에서VB COM 을 접근하는Thread는 단지1개만 존재해야 합니다. 그래서Single Thread Apartment 라는 용어가 됩니다.

Thread affinity

Single Thread Apartment 안에서 1개 이상의Thread가 동일한 또는 다른Object 를 이용(Object Context의 생성이 되겠죠.)하려고 한다면 STA 안에서는Message Queue 를 이용하게 합니다. Thread의 요청이Queue 안에 순차적으로 쌓이고 Queue out 하면서 한번에 하나씩 처리를 하면서 동기화 합니다. 물론, MTA는 이와 같은 구조가 아니므로, 동기화에 해당하는 강구(WaitForSingleObject/WaitForMultipleObjejcts API 이용)가 필요합니다만, STA는 내부적으로 이런 동기화 지원을 합니다. 그러므로, Thread affinity 라는 용어도 사용합니다. 일반적으로 동기화가 되기 때문에Thread Local Storage 와 같은 영역이 보장이 됩니다.

Causality

조금은 다른 말이 될 수 있는 데, DCOM 구조가 있습니다. 필요에 의해서 다른Process에서 수행되고 있는Object 를 이용하는 경우도 있습니다. DLLHOST.exe에서 surrogate 되고 있는COM의 경우가 대표적인 상황입니다. 이 경우에는 다른Process안의STA 에Object가 존재하고 있지만, RPC Channel 을 통해서 해당Object를 이용할 수 있습니다. 만일, A 라는Process안의 임의의 Thread가 A process안의STA 에 있는Object a 를 호출하고, 해당Object a 는 RPC Channel을 통해 B 라는Process안의 임의의 Thread로 하여금 MTA 혹은STA 안의 b 라는Object를 이용하는 구조를 생각해 봅시다. 이런 경우A Process의Thread와B process의 Thread는 당연히 서로 다른 구별된Thread입니다. 하지만, Logical 하게는 하나의Thread 로 , 하나의 수행흐름으로 보입니다. 하여 이와 같은 논리적인Thread를 Causality라고 합니다. 그래서 이들은 하나의 CID 값을 내부적으로 갖습니다. 보통 MSDTC의Transaction 처리는 하나의CID로 길게 수행이 됩니다.

*Reentrancy

Causality 예에서는 다른 Process의Apartment에 접근하는Cross apartment형태입니다. Cross apartment 의 경우RPC Channel을 통해서Call 한 후Callback 을Asynchronous 하게Return 받아야 하는 구조입니다. MTA Model 에서는 Apartment에 다른 여러 개의 Thread가 존재하기 때문에 임의의Thread가Callback을return 받지만, STA Model 은 그것이 불가능합니다. 하여, 이러한 Cross Apartment Call을 위해서 마찬가지로Message Loop 를 이용합니다. message Queue에 던져놓고Callback 을 기다리는 겁니다. 그러므로, Cross Apartment Call에 대한 Callback은 일단Blocking이 되고 해당Apartment는 다른Thread의 요청을 받을 수 있습니다. 이 경우에Reentrancy 가 발생합니다. 또 다른Thread 또는Causality가 해당Apartment에 진입할 수 있습니다. 기존의Cross Apartment Call에 대한Causality 는 종료되지 않은 상태로 또 다른Causality 가 진행됩니다. 이 경우 두 번째Causality가STA를 소유하고 있으므로, Cross Apartment Callback은 두 번째Causality 가 완료될 때 까지는 처리되지 못합니다. 물론, 두 번째Causality가 또 다시Cross Apartment Call이 될 수 도 있고 또 다른 세 번째, 네 번째Causality 가 들어오게 되어Dead Lock 과 같은 현상이 발생할 수도 있습니다. 물론, 두 번째Causality가 종료되고 첫 번째Callback이 이어서 종료되는 것이 정상적인 동작이 될 수도 있습니다.


이와 같은STA Reentrancy 현상은TLS 에도 영향을 미칩니다. 특히, VB Application의 경우는TLS에Global Variable이나, App, Err 내부적인Objects를 저장하고 있습니다. 이와 같은Reentrancy 는TLS가share되는 현상이 발생할 수 있기 때문에TLS Lock( *Activity Lock의 형태*)이나, Multiple Thread 환경에서 사용되는VB Application은Global Variable 을 사용하지 말라는Guide (http://support.microsoft.com/?id=815053) 를 하고 있습니다.


*Activity Lock 은 COM+ 에서 제공하는 Serialization을 이용한다고 보시면 됩니다.
*COM+ Catalog에서 STA Pool에 존재하는Thread 수를Monitoring 하다 보면, Reentrancy 로 인하여Max Pool 수보다 많은 수가 나오는 것도 경험할 수 있습니다.

STA는 Thread의 동기화를 걱정 할 필요가 없기때문에 편리하긴 하지만, Message Queue 의구조나 Message Queue를 사용하면서 발생하는 Thread switch, 그리고, Reentrancy에 의한 Dead Lock 이 발생할 수 도 있음을 고려해야 합니다. 그러므로, Multiple Threads 환경인 COM+ 나 IIS, 그리고, IE에서 VB AX(STA 기반의Component)를 사용 하는것은 많은 Issue를 유발 할 수 밖에 없을 것 같습니다. ( 사실VB 로만든 Component가 아니라면 더이상 STA는 보기 어려울 듯 합니다만.. 이제 그수명이 한 10개월정도 남은 것 같습니다.. )


덧글

  • George 2017/06/18 18:07 # 삭제 답글

    Thank you for some other informative website. Where else may just I am getting that kind of info written in such an ideal means? I've a venture that I am just now working on, and I have been on the glance out for such info.
  • David 2017/06/22 13:46 # 삭제 답글

    coumadin valtrex interaction
  • George 2017/07/19 10:54 # 삭제 답글

    you are in point of fact a just right webmaster. The site loading velocity is amazing. It sort of feels that you are doing any distinctive trick. Furthermore, The contents are masterpiece. you've performed a magnificent process in this subject!
  • Joseph 2017/08/02 05:35 # 삭제 답글

    It's truly a great and useful piece of information. I'm satisfied that you shared this helpful information with us. Please stay us informed like this. Thank you for sharing.
  • Michael 2017/08/05 23:58 # 삭제 답글

    Great, thanks for sharing this article. Really Cool.
  • Michael 2017/08/09 00:22 # 삭제 답글

    My own wife and I fell over here by a poles apart trap forward also contemplated I'd personally restraint points unconscious. I like exactly what I envision i really am located absolutely charting you. Look forward to
  • Mark 2017/08/29 05:08 # 삭제 답글

    Hello! Someone in my Facebook group shared this website with us so I came to check it out. I'm definitely enjoying the information. I'm bookmarking and will be tweeting this to my followers! Outstanding blog and superb design and style.
  • Robert 2017/09/07 16:40 # 삭제 답글

    Perfect webpage you have at this website! Precisely how could i add in this blog's feed into my Rss reader?
  • Robert 2017/09/28 00:49 # 삭제 답글

    Enjoyed examining this, very good stuff, thankyou. Talk sense to a fool and he calls you foolish. by Euripides.
  • Paul 2017/10/04 23:37 # 삭제 답글

    Whats Taking place i am new to this, I stumbled upon this I have found It positively helpful and it has aided me out loads. I hope to contribute &amp assist other users like its helped me. Great job.
  • George 2017/10/13 07:25 # 삭제 답글

    We're a group of volunteers and starting a new scheme in our community.
  • Mark 2017/10/16 02:17 # 삭제 답글

    This design is wicked! You obviously know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog well, almostHaHa! Wonderful job. I really enjoyed what you had to say, and more than that, how you presented it. Too cool!
  • Paul 2017/10/20 00:31 # 삭제 답글

    hello!,I like your writing very a lot! proportion we keep in touch more approximately your article on AOL? I require a specialist on this area to unravel my problem. May be that's you! Looking forward to look you.
  • Charles 2017/10/28 04:59 # 삭제 답글

    Hi there. Merely desired to question an instant dilemma.
  • James 2017/10/28 20:30 # 삭제 답글

    My brother recommended I may like this website. He used to be totally right. This post truly made my day. You can not consider simply how so much time I had spent for this info! Thanks!
  • James 2017/11/03 06:45 # 삭제 답글

    Today, I went to the beach front with my kids.
  • Charles 2017/11/16 14:39 # 삭제 답글

    Ive learn some excellent stuff here. Certainly worth bookmarking for revisiting. I wonder how a lot attempt you set to create such a fantastic informative web site.
  • Daniel 2017/11/29 10:19 # 삭제 답글

    nasa, , harold hill
  • Thomas 2017/12/01 05:21 # 삭제 답글

    Amoxicillin And Clavulanate 250mg With No Prescription in Indianapolis
  • Donald 2017/12/02 09:29 # 삭제 답글

    While think this kind of Real estate property industry hope against hope turn back in the positive course? Or maybe can it be at a standstill very young to tell? We're glimpse many terracing property foreclosures modish
  • Michael 2017/12/03 06:37 # 삭제 답글

    My spouse and I stumbled over here by a different internet address and thought I might check items out. I like what I see so i am just following you. Appear forward to checking out your web page again.
  • James 2017/12/05 01:01 # 삭제 답글

    Howdy very nice web site!! Guy .. Excellent .. Superb .. I'll bookmark your web site and take the feeds additionallyI am glad to search out so many helpful info here in the put up, we want develop more techniques in this regard, thanks for sharing.
  • David 2017/12/07 21:34 # 삭제 답글

    This website is mostly a walkby for all the info you wished about this and didnt know who to ask. Glimpse right here, and also youll undoubtedly uncover it.
  • Mark 2017/12/09 00:19 # 삭제 답글

    what are some superior and in demand websites for blogs? ?? .
  • Daniel 2017/12/12 04:28 # 삭제 답글

    Wow! This could be one particular of the most useful blogs We've ever arrive across on this subject. Basically Wonderful. I'm also a specialist in this topic so I can understand your hard work.
  • James 2017/12/15 03:22 # 삭제 답글

    I do not even know how I stopped up here, however I assumed this put up was good. I do not recognise who you are however definitely you're going to a wellknown blogger for those who are not already
  • Mark 2017/12/16 22:15 # 삭제 답글

    Some really nice and useful information on this web site, also I conceive the style and design holds superb features.
  • George 2017/12/20 06:12 # 삭제 답글

    Thanks for this article. I might also like to say that it can end up being hard if you find yourself in school and merely starting out to create a long credit rating. There are many learners who are only trying to endure and have long or good credit history are often a difficult issue to have.
  • Thomas 2017/12/26 13:01 # 삭제 답글

    I'm really enjoying the themedesign of your website. Do you ever run into any internet browser compatibility issues? A handful of my blog audience have complained about my site not operating correctly in Explorer but looks great in Firefox. Do you have any solutions to help fix this problem?
  • Donald 2017/12/28 10:38 # 삭제 답글

    Your goal is to breed all the different dragons available
  • James 2018/01/03 01:52 # 삭제 답글

    Magnificent website. Lots of useful information here. Im sending it to some friends ans also sharing in delicious. And obviously, thanks for your sweat!
  • William 2018/01/08 22:11 # 삭제 답글

    Hello, Neat post. There is a problem with your website in web explorer, may check this IE still is the market leader and a large component of folks will leave out your magnificent writing because of this problem.
  • James 2018/01/13 08:42 # 삭제 답글

    Some genuinely great information, Glad I discovered this. Good teaching is onefourth preparation and threefourths theater. by Gail.
  • John 2018/01/16 12:09 # 삭제 답글

    I have recently started a site, the info you provide on this website has helped me tremendously. Thanks for all of your time &amp work. The achievements of an organization are the results of the combined effort of each individual. by Vince Lombardi.
  • James 2018/01/20 09:22 # 삭제 답글

    Article Source a viral game app is not
  • William 2018/01/23 08:40 # 삭제 답글

    Because here is a list of multiplayer games is that the leave was asked
  • Robert 2018/01/31 10:41 # 삭제 답글

    I conceive this website has got some rattling superb info for everyone. Dealing with network executives is like being nibbled to death by ducks. by Eric Sevareid.
  • William 2018/02/01 22:18 # 삭제 답글

    you are in point of fact a just right webmaster. The site loading velocity is amazing. It sort of feels that you are doing any distinctive trick. Furthermore, The contents are masterpiece. you've performed a magnificent process in this subject!
  • Robert 2018/02/01 22:18 # 삭제 답글

    An interesting dialogue is value comment. I feel that it is best to write extra on this subject, it won't be a taboo subject but generally persons are not sufficient to speak on such topics. To the next. Cheers
  • Mark 2018/02/02 10:10 # 삭제 답글

    Hello there, i am interested
  • Richard 2018/02/07 07:22 # 삭제 답글

    Please add more movies related to cooking if you have, because I wish for to learn more and more about all recipes of cooking.
  • Paul 2018/02/24 11:17 # 삭제 답글

    Hmm it looks like your site ate my first comment it was extremely
  • Donald 2018/02/26 06:47 # 삭제 답글

    Really informative article post.Thanks Again. Awesome.
  • Mark 2018/03/31 04:15 # 삭제 답글

    Awesome article post.Thanks Again. Much obliged.
  • David 2018/04/24 12:16 # 삭제 답글

    I have read several good stuff here. Certainly worth bookmarking for revisiting. I surprise how much effort you put to make such a magnificent informative web site.
  • Mark 2018/05/05 01:28 # 삭제 답글

    I will immediately grab your rss feed as I can not find your email subscription link or enewsletter service. Do you have any? Kindly let me know so that I could subscribe. Thanks.
  • Paul 2018/06/02 17:13 # 삭제 답글

    A megapolis megabucks gratuit failed to seem to cause waste materials in addition
  • William 2018/06/05 19:31 # 삭제 답글

    Nice post. I study one thing more difficult on completely different blogs everyday.
  • Thomas 2018/06/13 01:51 # 삭제 답글

    When choosing the colours for you office, there are a few basic points to consider.
  • Donald 2018/06/13 17:52 # 삭제 답글

    I really appreciate this post. I've been looking all over for this! Thank goodness I found it on Bing. You've made my day! Thanks again!
  • George 2018/06/16 15:16 # 삭제 답글

    This kind of game gives a real experience of building a farm and planting
  • Michael 2018/06/18 17:45 # 삭제 답글

    I've read some excellent stuff here. Definitely price bookmarking for revisiting. I surprise how much effort you place to create this type of great informative site.
  • George 2018/06/27 20:17 # 삭제 답글

    Howdy! Would you mind if I share your blog with my twitter group? Theres lots of people that I believe would really enjoy your content. Please let me know. Thanks
  • William 2018/06/29 18:28 # 삭제 답글

    Hey esto es un gran poste. Puedo utilizar una porcin en ella en mi sitio? Por supuesto ligara a su sitio as que la gente podra leer el artculo completo si ella quiso a. Agradece cualquier manera.
  • James 2018/07/03 12:25 # 삭제 답글

    What sites and blogs perform searching district interact most on?
  • David 2018/07/07 00:10 # 삭제 답글

    Hello, I desire to subscribe for this blog to obtain most recent updates, thus where can i do it please help.
  • Daniel 2018/07/24 15:27 # 삭제 답글

    Superb post but I was wanting to know if you could write a
  • John 2018/07/27 14:16 # 삭제 답글

    I will immediately clutch your rss feed as I can not to find your email subscription link or enewsletter service. Do you have any? Please let me know in order that I may just subscribe. Thanks.
  • Richard 2018/07/31 18:51 # 삭제 답글

    Heya im for the first time here. I found this board and I find It really useful &amp it helped me out much. I hope to give something back and help others like you aided me.
  • William 2018/08/05 05:11 # 삭제 답글

    Hello, Neat post. There's a problem with your web site in web explorer, may test thisK IE still is the market leader and a large component to people will leave out your magnificent writing due to this problem.
  • William 2018/08/10 20:37 # 삭제 답글

    I got what you mean, regards for putting up.Woh I am delighted to find this website through google. You must pray that the way be long, full of adventures and experiences. by Constantine Peter Cavafy.
  • James 2018/08/22 17:03 # 삭제 답글

    I dugg some of you post as I cogitated they were very useful extremely helpful
  • David 2018/08/24 09:41 # 삭제 답글

    requirements. Recognitions pro suggestion like operative, balanced, explanatory as well as moreover exuberance thinkings about this issue to Gloria.
  • James 2018/08/30 02:34 # 삭제 답글

    This kind of game gives a real experience of building a farm and planting trees.
  • James 2018/09/01 19:06 # 삭제 답글

    Several of these games are worth some time and are actually quite fun.
  • John 2018/09/04 07:44 # 삭제 답글

    coumadin valtrex interaction
  • Charles 2018/09/06 18:59 # 삭제 답글

    mometasone spray over counter
  • Joseph 2018/09/22 14:23 # 삭제 답글

    Fckin amazing things here. Im very glad to see your post. Thanks a lot and i'm looking forward to contact you. Will you kindly drop me a mail?
  • Michael 2018/09/25 09:29 # 삭제 답글

    It's perfect time to make some plans for the long run and it is time to be happy. I have learn this publish and if I may I want to suggest you few attentiongrabbing things or advice. Maybe you could write next articles regarding this article. I desire to read even more things about it!
  • John 2018/09/27 13:41 # 삭제 답글

    Dead written subject material, Really enjoyed studying.
  • Donald 2018/09/29 02:18 # 삭제 답글

    Very efficiently written information. It will be beneficial to everyone who employess it, including myself. Keep up the good work for sure i will check out more posts.
  • William 2018/10/01 07:27 # 삭제 답글

    I do consider all the ideas you've presented on your post. They're really convincing and can certainly work. Still, the posts are very brief for novices. May just you please extend them a little from next time? Thanks for the post.
  • James 2018/10/04 13:26 # 삭제 답글

    I will immediately clutch your rss feed as I can not to find your email subscription link or enewsletter service. Do you have any? Please let me know in order that I may just subscribe. Thanks.
  • Charles 2018/10/05 00:34 # 삭제 답글

    Ive learn some excellent stuff here. Certainly worth bookmarking for revisiting. I wonder how a lot attempt you set to create such a fantastic informative web site.
  • William 2018/10/06 21:51 # 삭제 답글

    griseofulvin psoriasis
  • Donald 2018/10/07 09:01 # 삭제 답글

    hello!,I like your writing very a lot! proportion we keep in touch more approximately your article on AOL? I require a specialist on this area to unravel my problem. May be that's you! Looking forward to look you.
  • Daniel 2018/10/08 16:39 # 삭제 답글

    I like what you guys tend to be up too. Such clever work and coverage! Keep up the very good works guys I've incorporated you guys to my personal blogroll.
  • Michael 2018/10/10 02:12 # 삭제 답글

    hello!,I like your writing so much! share we keep up a correspondence extra about your article on AOL? I require an expert on this space to resolve my problem. May be that is you! Looking ahead to look you.
  • William 2018/10/10 15:10 # 삭제 답글

    Over the course of the initial period, they began to flrm group identities.
  • Mark 2018/10/12 14:40 # 삭제 답글

    Thanks for this article. I might also like to say that it can end up being hard if you find yourself in school and merely starting out to create a long credit rating. There are many learners who are only trying to endure and have long or good credit history are often a difficult issue to have.
  • Robert 2018/10/14 03:05 # 삭제 답글

    Heya im for the first time the following. I discovered this specific table as a consequence I to discover The item faithfully of use &amp the idea rallied round myself publicized lots. I am hoping to deliver a little back again furthermore foster further like so
  • Robert 2018/10/15 06:51 # 삭제 답글

    Thank you for the good writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! By the way, how can we communicate?
  • John 2018/10/16 23:12 # 삭제 답글

    Thank you for some other informative website. Where else may just I am getting that kind of info written in such an ideal means? I've a venture that I am just now working on, and I have been on the glance out for such info.
  • James 2018/10/17 23:46 # 삭제 답글

    Hello there, i am interested
  • James 2018/10/19 09:19 # 삭제 답글

    I truly appreciate this post. I've been looking all over for this! Thank goodness I found it on Bing. You've made my day! Thanks again!
  • William 2018/10/21 07:17 # 삭제 답글

    Howdy! Would you mind if I share your blog with my twitter group? Theres lots of people that I believe would really enjoy your content. Please let me know. Thanks
  • James 2018/10/21 14:18 # 삭제 답글

    You're so interesting! I don't think I have read anything like this before. So wonderful to discover somebody with some unique thoughts on this subject matter. Seriously.. thank you for starting this up. This website is one thing that is needed on the internet, someone with a bit of originality!
  • Michael 2018/10/24 14:18 # 삭제 답글

    Well I really enjoyed reading it. This information procured by you is very practical for correct planning.
  • Paul 2018/10/24 16:12 # 삭제 답글

    mometasone spray over counter
  • James 2018/10/28 15:23 # 삭제 답글

    Hi there! This is my first visit to your blog! We are a group of volunteers and starting a new initiative in a community in the same niche. Your blog provided us beneficial information to work on. You have done a marvellous job!
  • James 2018/10/29 06:04 # 삭제 답글

    My brother recommended I may like this website. He used to be totally right. This post truly made my day. You can not consider simply how so much time I had spent for this info! Thanks!
  • David 2018/10/30 20:18 # 삭제 답글

    Farmville farms even include free gift that
  • James 2018/11/01 10:08 # 삭제 답글

    I just couldn't depart your site before suggesting that I actually enjoyed the standard information a person provide for your visitors? Is gonna be back often in order to check up on new posts
  • David 2018/11/01 10:10 # 삭제 답글

    I have learn some good stuff here. Certainly price bookmarking for revisiting.
  • Charles 2018/11/04 10:11 # 삭제 답글

    Where To Purchase AkChlor 250mg Without A Script
  • Mark 2018/11/05 04:56 # 삭제 답글

    Perfect webpage you have at this website! Precisely how could i add in this blog's feed into my Rss reader?
  • James 2018/11/07 05:53 # 삭제 답글

    I am sure this post has touched all the internet people, its really really nice post on building up new web site.
  • Daniel 2018/11/10 13:25 # 삭제 답글

    I think this is one of the most significant information for me. And i'm glad reading your article. But should remark on some general things, The web site style is wonderful, the articles is really excellent D. Good job, cheers
  • George 2018/11/12 03:10 # 삭제 답글

    omg! cant picture how quick time pass, after August, ber months time already and Setempber may be the 1st Christmas season in my location, I genuinely really like it!
  • John 2018/11/12 09:02 # 삭제 답글

    Enjoyed examining this, very good stuff, thankyou . While thou livest keep a good tongue in thy head. by William Shakespeare.
댓글 입력 영역
◀ 다음덧글    이전덧글 ▶