InitOnceExecuteOnce exception safety

I have a exception safety issue on InitOnceExecuteOnce WinAPI function. Whenever exception is thrown from callback function deadlock is occurred. Callback returns boolean flag telling the caller whether the data is successfully initialized, but if I return false I will not be able to rethrow exception, that's not good. I tried solved the problem this way.

try { InitOnceExecuteOnce(&flag, init_once_handler, &arguments, 0); } catch (...) { InitOnceInitialize(&flag); throw; }

Whenever I catch an exception from function I init the structure once again and rethrow the exception, so other threads will find the data not initialized, as the flag is in initial state. However, it sometimes deadlocks too, possibly because other thread started waiting on the synchronization object before the first one caught the exception and initialized flag once again. Is there any solution to that problem?

Thanks in advance.

-------------Problems Reply------------

You should not throw C++ exceptions through code that does not expect it, (eg. C code, or in your case, the Windows API). instead, have your callback return false on error, which will be reflected in the return from InitOnceExecuteOnce

Category:c# Views:0 Time:2011-01-27

Related post

  • Generic Method Type Safety 2008-09-17

    I have the concept of NodeTypes and Nodes. A NodeType is a bunch of meta-data which you can create Node instances from (a lot like the whole Class / Object relationship). I have various NodeType implementations and various Node implementations. In my

  • What is the best resource for learning about Safety Critical Systems Development (C/C++) 2008-09-17

    I'm looking to locate a good resource (book or otherwise) on safety critical systems development techniques/methodologies, especially something that will cover both hardware and software . I have a sound working knowledge of C/C++, so even if it is j

  • Java: Swing Libraries & Thread Safety 2008-10-08

    I've often heard criticism of the lack of thread safety in the Swing libraries. Yet, I am not sure as to what I would be doing in my own code with could cause issues: In what situations does the fact Swing is not thread safe come into play ? What sho

  • Is Agile programming too- ad hoc for safety-critical systems? 2008-10-24

    For example, would it be incredibly dangerous to do it for avionics software? Note, I don't completely understand Agile. --------------Solutions------------- I've worked on Air-Traffic Control systems using an essentially waterfall process, and those

  • Which languages are used for safety-critical software? 2008-10-28

    I'm researching the development of safety-critical software, and in particular what effects the choice of programming language has on such development. Please explain, in detail, which languages are commonly used, and why. --------------Solutions----

  • Thread safety of Matlab engine API 2008-10-29

    I have discovered through trial and error that the MATLAB engine function is not completely thread safe. Does anyone know the rules? Discovered through trial and error: On Windows, the connection to MATLAB is via COM, so the COM Apartment threading r

  • Best programming approach/methodology to assure thread safety 2008-11-02

    When I was learning Java coming from a background of some 20 years of procedural programming with basic, Pascal, COBOL and C, I thought at the time that the hardest thing about it was wrapping my head around the OOP jargon and concepts. Now with abou

  • Type safety: Unchecked cast 2008-11-04

    In my spring application context file, I have something like: <util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.lang.String"> <entry key="some_key" value="some value" /> <entry key="some_

  • Should we use Generic Collection to improve safety and performance? 2008-11-05

    Should we use Generic Collection to improve safety and performance? --------------Solutions------------- Of course. Why wouldn't you? More important than the performance, IMO, is the fact that generic APIs are more expressive. That goes for generic A

  • ArrayList vs. Vectors in Java if thread safety isn't a concern 2008-11-18

    Is there really that much of a difference between the performance of Vector and ArrayList? Is it good practice to use ArrayLists at all times when thread safety isn't an issue? --------------Solutions------------- Vector originates back from the pre-

  • SharePoint and thread safety 2008-11-24

    I'm looking for articles, forum or blog posts dealing with SharePoint and thread safety? I'm quite sure there are some special aspects regarding thread safety that have to be considered when working with the SharePoint object model. Actually I didn't

  • In C# would it be better to use Queue.Synchronized or lock() for thread safety? 2008-12-03

    I have a Queue object that I need to ensure is thread-safe. Would it be better to use a lock object like this: lock(myLockObject) { //do stuff with the queue } Or is it recommended to use Queue.Synchronized like this: Queue.Synchronized(myQueue).what

  • Code Re-entrancy vs. Thread Safety 2008-12-09

    What is the difference between the concepts of "Code Re-entrancy" and "Thread Safety"? As per the link mentioned below, a piece of code can be either of them, both of them or neither of them. Reentrant and Thread safe code I was not able to understan

  • Thread-safety and concurrent modification of a table in SQLite3 2008-12-10

    Does thread-safety of SQLite3 mean different threads can modify the same table of a database concurrently? --------------Solutions------------- No - SQLite does not support concurrent write access to the same database file. SQLite will simply block o

  • Thread safety and `const` 2008-12-12

    How does const (pointers, references and member functions) help with thread safety in C++? --------------Solutions------------- The main problem with multiple threads is mutability. const restricts this, but since you can cast away the const-ness, it

  • Where is Ada used (apart from safety-critical software)? 2008-12-14

    When one thinks of Ada, one usually thinks of avionics. What I'm interested in are some other applications of Ada? Where is it used? Are there any shipped applications written in Ada? For example, are there CRUD apps written in it? Or games? Etc. ---

  • How to write an automated test for thread safety 2008-12-27

    I have a class which is not thread safe: class Foo { /* Abstract base class, code which is not thread safe */ }; Moreover, if you have foo1 and foo2 objects, you cannot call foo1->someFunc() until foo2->anotherFunc() has returned (this can happ

  • Declarative thread safety in .NET 2009-02-04

    I need to make an existing app thread safe. Due circumstances (see below), I decided to use one single ReaderWriterLock for the entire graph of business objects. All methods/properties must look like these: public int MyReadOperation(string inputPara

  • Static keyword, state/instance variables, and thread safety 2009-02-14

    First of all, the static keyword. I've read several articles and past threads on here covering the static keyword. I haven't found many scenarios listed of when I should use it. All I know is it doesn't create an object on the heap which tells me it

Copyright (C), All Rights Reserved.

processed in 0.065 (s). 11 q(s)