Why does using the NI-DAQmx ANSI C functions in a thread cause a deadlock?

First up, apologies if this is the wrong board but it seemed the closest fit.
I'm using MSVC 2008 Express with the NI DAQmx ANSI C library to perform some analogue output using a USB-6009. I am creating a thread to handle the generation of the signal as it is on a fixed timebase. My main thread runs the user interface. I have found that I get intermittent deadlocks in release mode while the NI libraries are being loaded (in the second thread) and I use some MSVCRT functions (on the main thread). My test code is attached as "deadlock2.cpp".
I have used WinDbg to try to find the cause of the deadlock. The stack traces of my two threads are attached as t1_stack.txt and t2_stack.txt.
It appears that the localtime() function from the MSVCRT uses a lock when it is called for the first time and then goes to lock the Windows DLL loader lock. At the same time the NI libraries (or at least mxs libraries) are being loaded so the DLL loader lock is being held. The mxsutils library uses getcwd() which appears to try to lock something in the MSVCRT and so my two threads are now deadlocked.
I can probably work around this by calling the localtime() and the NI DAQmx functions before I spawn my second thread so that the DLLs are already loaded into the process. However, I have no guarantees of this continuing to work if anything changes in the future, and if there are any locks going on then having the DllMain() called for a thread attach may still cause a deadlock. If my findings are correct is it likely that NI would fix the DLLs to not try to do anything complex in their DllMain()?
According to NI Measurement and Automation Explorer I'm running v9.3.5f2 of the DAQmx libraries. I'm downloading the latest version now to try but it will take some time.
Solved!
Go to Solution.
Attachments:
deadlock2.cpp ‏2 KB
t1_stack.txt ‏2 KB
t2_stack.txt ‏3 KB

Hi dmcminn,
Thank you for the detailed and complete bug report. I was able to reproduce the problem with NI-DAQmx 9.6 using the code you posted. I reported it to the appropriate R&D team as CAR #366538.
I agree with your analysis of the problem. Both getcwd() and the first call to __tzset() acquire _ENV_LOCK, which Microsoft has documented as the "lock for environment variables". __tzset() also calls GetTimeZoneInformation(), which may load additional libraries, as you have shown.
Here are a couple more potential workarounds, but they're not great:
Link to the static version of the CRT (/MT instead of /MD). This would link a separate copy of the CRT lock table into your program, and DAQmx would continue to use MSVCR90.dll's lock table. They would no longer use the same _ENV_LOCK.
Build using a different version of Microsoft Visual C++ (e.g. 2005 or 2010). MSVCR80.dll, MSVCR90.dll, and MSVCR100.dll own separate copies of the CRT lock table.
Either way, it doesn't eliminate the fact that mxsutils calls into the CRT while holding the loader lock, and that CRT function acquires another lock.
By the way, the Multifunction DAQ forum is a better place to post DAQmx questions.
Brad
Brad Keryan
NI R&D

Similar Messages

  • How to save data acquired from NI-DAQ in text format instead of TDMS using the DAQ-mx ANSI C code?

    Hi,
    I wanted to save data acquired from NI-DAQ (for example, NI 9234) in a file using the DAQ-mx ANSI C Code. The response I got was as follows:-
    One way to do it is with TDMS logging. DAQmx comes with functions designed to log to a TDMS file. This is a special file type that is used for collecting data in a logical format. It can be displayed in a TDMS viewer where data is separated into groups and channels. NI-DAQmx provides examples for how to log to TDMS. Look at the TDMS examples in the C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage directory.
    However, now I want to know is there a way that using that same C code, can we save the data in a .txt file format (Text File) instead of a TDMS file? We actually want to access that file through MATLAB (that's why we want to save it in text format).
    Also on an other note, is there a way we can access & open TDMS files by MATLAB?
    Thanks,
    Sauvik Das Gupta

    There's a way you can access TDMS files in MATLAB:
    http://zone.ni.com/devzone/cda/tut/p/id/7446

  • Why does useful features are limited to few adapters?

    Why does useful features are limited to few adapters?
    For eg : File receiver CC has a option to stop Empty messages from being processed.
    This is not available in SOAP receiver.
    Is it possible to have a standard adapter module in SOAP receiver CC that will achieve this?
    Regards,
    Venkat.

    >
    Venkat A wrote:
    > Why does useful features are limited to few adapters?
    > For eg : File receiver CC has a option to stop Empty messages from being processed.
    > This is not available in SOAP receiver.
    Thats for SAP to answer i guess
    Well initially there was no option in the File adapter to handle empty messages but as requirement grew and more and more customers/consultants were in need to handle such a functionality, SAP brought it in through a SP release
    Maybe if this particular requirement of your finds popularity, then SAP might come up with a inbuilt solution
    >
    > Is it possible to have a standard adapter module in SOAP receiver CC that will achieve this?
    >
    > Regards,
    > Venkat.
    in you case why do you need to send the SOAP receiver a empty message??
    If you need to handle it then the best is to do some workaround in the mapping and have a field in your target structure indicate that it is a empty message (something like a flag) and then do the routing logic based on this flag.

  • HT2731 Does using the same Apple ID on my iPhone and iPod touch use my phones data plan?

    Does using the same Apple ID on my iPhone and iPod touch use my phones data plan?

    If you are using the internet then it's eating away at your data plan, irrespective of your Apple ID.
    Here's an article about data plans:
    http://voip.about.com/od/voipbandwidth/a/What-Is-A-Data-Plan.htm

  • Why to use the Java API in MDM

    Hi Experts,
    I am new to the MDM.
    We are having the requirement of inetration between Portal and MDM.Can u please tell me when to use the following coponents like the scenorio's.
    Why to install the MDM Business packages in Portal?
    why to use the JAVA API.
    Please give me the complete information.
    Regards

    Hi Vijay,
    Standard Business Package is use to provide interaction between MDM Server and the Portal. It consists of MDM iViews like Item Detail iView (allows to create,edit and delete the records) , Resultset iView (Displays the records, allows to add the records in workflows etc), Search iViews (for searching)i.e. Data Manager functionality.
    Java API are used when you need some functionality that standard MDM iViews dont have.MDM Java API consists of set of classes and interfaces with the help of which customization can be done.
    Regards,
    Jitesh Talreja

  • Why does not the text "Powered by Adobe Forms Central" fästän man has paid form

    Why does not the text "Powered by Adobe Forms Central" fästän man has paid form
    [email protected]

    These forms are not embedded correctly. I'm surprised they even work. You need to go to the distribute tab, click Embed button, copy the embed code provided and then paste that into your HTML. This FAQ explains in more detail and some of the issues you may encounter while embedding: http://forums.adobe.com/docs/DOC-1991
    Randy

  • Why does moving the cursor peg the cpu in numbers?

    Why does moving the cursor, even by one cell, peg the cpu in numbers?

    Hello
    Before posting yesterdays, I tested with a table of 4435 x 8 cells on the iMac described below.
    I will be more precise than yesterdays.
    Numbers recalculate the entire document after every change. A single new character is sufficient.
    Twenty years ago, AppleWorks designers were kind enough to recalculate only what really needed.
    It seems that new developers are not relying upon intelligence but upon processor's brute force.
    Their code will be efficient … on the machines which will be available within at least five years.
    Alas, at this time there will no longer be compatible with the operating system.
    Given this awful coding, when AutoSave apply, it must write on disk an entire new index.xml file.
    Same thing when Versions apply.
    Under SnowLeopard these two features don't strike.
    If you wish, you may send your 'offending' document to my mailbox so I will be able to check the way it behave here. Don’t worry, I don't take care of what is really stored, only of the doc's behavior.
    Click my blue name to get my address.
    Yvan KOENIG (VALLAURIS, France) jeudi 12 janvier 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

  • Why does not the scroll on tbody in new versions of Firefox and how it can solve the problem?

    why does not the scroll on tbody in new versions of Firefox and how it can solve the problem?

    scrolling overflow on tbody is no longer supported because that is not allowed in CSS 2.1 specification.
    See [https://developer.mozilla.org/en/CSS/overflow notes for overflow]

  • I have an original iPad and downloaded the new operating system.  Now' I cannot write on my Contacts or Calendar apps, and my Pages app (purchased) has lost the ability to use the bold, underline, and italics functions.  Does anyone know how to fix these

    I have an original iPad and downloaded the new operating system.  Now, I cannot add to my contacts or calendar apps, and Pages ( which I purchased) is not allowing me to use the bold, underline, and italics functions.  Does anyone know how to solve this problem?

    No, it stays with the current OS (iOS5 in this case) - Apple doesn't allow downgrading iOS
    If you are syncing to a desktop, you shoudln't lose anything. If you aren't syncing, then that's the first thing you should do, to protect contacts etc.
    the other thing is, when the iPad is connected to iTunes, right-click its name in the Devices list and choose Back Up.
    That way, when yoiu do the restore, everything should come back as was.

  • Why we use the LDAP Authentication over the DB authentication?

    Hi All,
    Why we use the LDAP Authentication over the DB authentication?
    Any specific region is for that?
    When we use LDAP do we need DB authentication again or it will be optional?
    In same case in ADSI do the DB authentication is optional or compulsory .
    Thanks in advance
    Tusar

    LDAP / AD authentication is useful if you already use it in your organisation and you'll find that most orgs have some form of user authentication already in place.
    Do users in your company have to log into to their machines every morning? If so, why not use those credentials to control access to Siebel? It's a way of providing a single directory of employee authentication information available across applications, keeping maintenance and change costs down.
    When you use LDAP authentication, you specify an AD object that contains a set of DB authentication details so that the component can access the Siebel database. In Siebel 8, you can directly specify those details in the security profile. As such, you only then have to maintain a single set of DB specific authentication details: much easier to manage. You can always switch back to DB authentication if you want to, but you'd have to go through all users accounts and create them with the same login and password specified in AD.

  • Why does pressing the L key twice (to cycle through dimming modes) remove a selected photo from a collection?

    That's my question, Why does pressing the L key twice (to cycle through dimming modes) remove a selected photo from a collection? Is my system the only computer that does this when I follow Adobe's directions to cycle through dimming modes by repeatedly hitting L? If not, how dumb is this?

    Hi,
    Check below things
    ---ManagerRendered attribute is transientAttr and type:Boolean
    ---${oa.viewInsatnce.ManagerRendered} ...paste in Readonly property of the item.
    OARow detailsRow = (OARow)detailsVO.*first()*;
    String position=(String)detailsRow.getAttribute("PositionCode");
    String firstname=(String)detailsRow.getAttribute("FirstName");
    System.out.println(firstname); The firstname is got from detailsRow correctly if I entered it on page.
    if ((position == null) && ("PRESIDENT".equals(position)))
    detailsRow.setAttribute("ManagerRendered", Boolean.FALSE);
    else
    detailsRow.setAttribute("ManagerRendered", Boolean.TRUE);
    Regards
    Meher Irk

  • Hi. Does using the cover lock help battery life?

    Hi. Does using the cover lock help battery life?

    The quickest way (and really the only way) to charge your iPad is with the included 10W USB Power Adapter. iPad will also charge, although more slowly, when attached to a computer with a high-power USB port (many recent Mac computers) or with an iPhone Power Adapter (5W). When attached to a computer via a standard USB port (most PCs or older Mac computers) iPad will charge very slowly (but iPad indicates not charging). Make sure your computer is on while charging iPad via USB. If iPad is connected to a computer that’s turned off or is in sleep or standby mode, the iPad battery will continue to drain.
    Apple recommends that once a month you let the iPad fully discharge & then recharge to 100%.
    How to Calibrate Your Mac, iPhone, or iPad Battery
    http://www.macblend.com/how-to-calibrate-your-mac-iphone-or-ipad-battery/
    At this link http://www.tomshardware.com/reviews/galaxy-tab-android-tablet,3014-11.html , tests show that the iPad 2 battery (25 watt-hours) will charge to 90% in 3 hours 1 minute. It will charge to 100% in 4 hours 2 minutes. The new iPad has a larger capacity battery (42 watt-hours), so using the 10W charger will obviously take longer. If you are using your iPad while charging, it will take even longer. It's best to turn your new iPad OFF and charge over night. Also look at The iPad's charging challenge explained http://www.macworld.com/article/1150356/ipadcharging.html
    Also, if you have a 3rd generation iPad, look at
    Apple: iPad Battery Nothing to Get Charged Up About
    http://allthingsd.com/20120327/apple-ipad-battery-nothing-to-get-charged-up-abou t/
    Apple Explains New iPad's Continued Charging Beyond 100% Battery Level
    http://www.macrumors.com/2012/03/27/apple-explains-new-ipads-continued-charging- beyond-100-battery-level/
    New iPad Takes Much Longer to Charge Than iPad 2
    http://www.iphonehacks.com/2012/03/new-ipad-takes-much-longer-to-charge-than-ipa d-2.html
    Apple Batteries - iPad http://www.apple.com/batteries/ipad.html
    Extend iPad Battery Life (Look at pjl123 comment)
    https://discussions.apple.com/thread/3921324?tstart=30
    New iPad Slow to Recharge, Barely Charges During Use
    http://www.pcworld.com/article/252326/new_ipad_slow_to_recharge_barely_charges_d uring_use.html
    Tips About Charging for New iPad 3
    http://goodscool-electronics.blogspot.com/2012/04/tips-about-charging-for-new-ip ad-3.html
    Prolong battery lifespan for iPad / iPad 2 / iPad 3: charging tips
    http://thehowto.wikidot.com/prolong-battery-lifespan-for-ipad
    iPhone, iPod, Using the iPad Charger
    http://support.apple.com/kb/HT4327
    Install and use Battery Doctor HD
    http://itunes.apple.com/tw/app/battery-doctor-hd/id459702901?mt=8
    In rare instances when using the Camera Connection Kit, you may notice that iPad does not charge after using the Camera Connection Kit. Disconnecting and reconnecting the iPad from the charger will resolve this issue.
     Cheers, Tom

  • Can't use the Calendar, Book, and Card functions

    I have updated my iLife programs to iLife 08 and cannot use the Calendar, Book, and Card functions as the program says the themes have not been installed. However, after looking in the Library/Applications Support/iPhoto folder, the themes are there but not being recognized by the program. I have reinstalled iLife 08 but still to no avail. Help!

    Grant:
    Try the following:
    A. look for a folder title Themes in the User/Library/Application Support/iPhoto folder. If you find one there move it to the HD/Library/Application Support/iPhoto folder and reboot.
    If that doesn't jump start iPhoto then go on to B.
    B.
    Restoring iPhoto Themes
    1 - delete the current application.
    2 - delete any files with iPhoto in the file name that reside in your HD/Library/Receipts folder.
    3 - delete the Themes folder from your User/Library/Application Support/iPhoto folder.
    Also look in the HD/Library/Application Support/iPhoto folder for a Themes folder. If there is one there then delete it also.
    5 - boot into the system disk that came with your computer and do a custom install selecting only iPhoto.
    After installing reinstall the iPhoto 7.1.1 updater again followed by a repair of disk permissions with Disk Utility. Also make sure you're running the latest Quicktime, 7.3.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • How do I transfer itunes music to my iphone 4 without using the restore from this backup function?

    How do I transfer itunes music to my iphone 4 without using the restore from this backup function?  I cannot use the back up function as have been advised that therer are bugs in it and restoring it back to my phone will bring the bugs with it and phone will be back to apple again as will start playing up again.  But I need the music.  Whn I plug it in laptop and go to itunes icon it gives me 2 options:  Set up as new iphone? OR Restore from backup.
    Do I pick set up as new phone?  I dont know as the guy at the genius bar told me there would be an option asking if i want to sync itunes only...but there isn't.

    Set up as New and then... Re-Sync your Content from iTunes.
    SYNCING with iTunes
    See here  >  http://support.apple.com/kb/HT1386
    From Here  >  http://www.apple.com/support/iphone/syncing/

  • I cant use the highlight, underline, or strikethrough function in a specific pdf file. The file isnt locked. I used to highlight texts from that file before the latest update. The problem occurs only with that file. Urgent need. Please help. Thanks!

    i cant use the highlight, underline, or strikethrough function in a specific pdf file. The file isnt locked. I used to highlight texts from that file before the latest update. The problem occurs only with that file. Urgent need. Please help. Thanks!

    Chester31,
    Thank you very much for sharing your file with us!  Now that we are able to reproduce the problem at our end, you may stop sharing the file on Acrobat.com.
    Do you know when this problem (for not being able to add new highlight/strikeout/underline) has started?  Did you update your iOS from 7.x to 8.0 recently?
    We will continue investigating the problem and let you know what we find.
    Thank you again for your help.

Maybe you are looking for