Hi All, I’ve recently discovered a strange Cygwin bug on Windows 8. Calling SetupDiGetDeviceRegistryProperty() from a Cygwin thread created with pthread_create() causes it fail unconditionally. This actually breaks libusb for any program that uses it outside the main thread. The bug can be reproduced with a small program below. Could anyone please advise me if this could be fixed in one of the next Cygwin releases? Best regards, Ivan Shcherbakov Repro case (g ++ thread_repro.cpp -o thread_repro.exe -lsetupapi && ./thread_repro): #include <windows.h> #include <SetupAPI.h> #include <pthread.h> #include <stdio.h> void list_devices(int maxCount) { HDEVINFO hDevInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_PRESENT | DIGCF_ALLCLASSES); SP_DEVINFO_DATA devinfo = { sizeof(devinfo) }; for (int i = 0; i < maxCount && SetupDiEnumDeviceInfo(hDevInfo, i, &devinfo); i++) { DWORD dataType = 0; char szData[1024] = { 0, }; if (SetupDiGetDeviceRegistryPropertyA(hDevInfo, &devinfo, SPDRP_HARDWAREID, &dataType, (BYTE *) szData, sizeof(szData), NULL)) printf("%d: %s\n", i, szData); else printf("%d - error %d\n", i, GetLastError()); devinfo.cbSize = sizeof(devinfo); } SetupDiDestroyDeviceInfoList(hDevInfo); } void* thread_body(void *) { printf("Listing devices from a pthread\n"); list_devices(10); return 0; } int main() { printf("Listing devices from the main thread\n"); list_devices(10); pthread_t t; pthread_create(&t, NULL, thread_body, 0); pthread_join(t, NULL); return 0; }
The output on Windows 8: Listing devices from the main thread 0: USB\VID_0E0F&PID_0007&REV_0100 1: ACPI\VEN_PNP&DEV_0100 2: STORAGE\Volume 3: PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01 4: PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01 5: PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01 6: PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01 7: PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01 8: PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01 9: PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01 Listing devices from a pthread 0 - error 13 1 - error 13 2 - error 13 3 - error 13 4 - error 13 5 - error 13 6 - error 13 7 - error 13 8 - error 13 9 - error 13 -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple