SBC2: Bug in Phidget22 C library (20190116) Phidget_finalize

C, C++, and Visual C++
Post Reply
TestUzer
Phidgetsian
Posts: 9
Joined: Thu Jan 18, 2018 7:13 am
Contact:

SBC2: Bug in Phidget22 C library (20190116) Phidget_finalize

Post by TestUzer »

I've been working on my little application and was noticing on rare occasions mutex exceptions were being thrown, so I did some testing. After a while it was apparent that, calling Phidget_finalize(0); when exiting causes a subsequent execution to occasionally throw the exception shown below.

Code: Select all

lock 0x40286da0 failed with 22 (Success)
Test2: src/ext/mos/mos_lock-pthread.c:292: mos_mutex_lock: Assertion `res == 0' failed.
When Phidget_finalize is removed the exception is not thrown.

I'm guessing that by not using Phidget_finalize the library is actually recycling resources between calls so the mutex is never actually released.

By doing Phidget_finalize the library seems to be releasing the mutex but not marking the resource gone. On the next execution the library tries to recycle the resources but throws the exception as the mutex has gone.

There is sample code below and a full project in the attached zip. To test the code, compile and use the testloop shell script. Remember to chown the script.

Run it for a couple of minutes to see the exception.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>


#include <phidget22.h>
#include "PhidgetHelperFunctions.h"

int main() {
	PhidgetVoltageRatioInputHandle ch = NULL;
	PhidgetReturnCode prc;
     double sensorValue;

		prc = PhidgetVoltageRatioInput_create(&ch);
		CheckError(prc, "Creating Channel", (PhidgetHandle *)&ch);

		prc = Phidget_setDeviceSerialNumber((PhidgetHandle)ch, -1);
		CheckError(prc, "Setting DeviceSerialNumber", (PhidgetHandle *)&ch);

		prc = Phidget_setHubPort((PhidgetHandle)ch, -1);
		CheckError(prc, "Setting HubPort", (PhidgetHandle *)&ch);

		prc = Phidget_setIsHubPortDevice((PhidgetHandle)ch, 0);
		CheckError(prc, "Setting IsHubPortDevice", (PhidgetHandle *)&ch);

		prc = Phidget_setChannel((PhidgetHandle)ch, 0);
		CheckError(prc, "Setting Channel", (PhidgetHandle *)&ch);

		prc = Phidget_openWaitForAttachment((PhidgetHandle)ch, 5000);
		CheckOpenError(prc, (PhidgetHandle *)&ch);

		Sleep(100);
          PhidgetVoltageRatioInput_getSensorValue(ch, &sensorValue);

		prc = Phidget_close((PhidgetHandle)ch);
		CheckError(prc, "Closing Channel", (PhidgetHandle *)&ch);

		prc = PhidgetVoltageRatioInput_delete(&ch);
		CheckError(prc, "Deleting Channel", (PhidgetHandle *)&ch);

   // if the following line is removed no exception is thrown
   Phidget_finalize(0);
   Sleep(1000);

   return 0;
}
Attachments
Test2.zip
(5.93 KiB) Downloaded 472 times
User avatar
Patrick
Lead Developer
Posts: 3403
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: SBC2: Bug in Phidget22 C library (20190116) Phidget_finalize

Post by Patrick »

This bug is fixed in the next release
TestUzer
Phidgetsian
Posts: 9
Joined: Thu Jan 18, 2018 7:13 am
Contact:

Re: SBC2: Bug in Phidget22 C library (20190116) Phidget_finalize

Post by TestUzer »

Have done an update/upgrade with a restart. Library is reported as "Phidget22 - Version 1.0.0 - Built Jan 29 2019 11:16:26"

Recompiled and executed the test code via script "testloop" from my previous message.

Got a slightly different error message "Invalid argument" (was "Success") at the same line on the same assertion.

Code: Select all

lock 0x40300ea0 failed with 22 (Invalid argument)
Test2: src/ext/mos/mos_lock-pthread.c:292: mos_mutex_lock: Assertion `res == 0' failed.
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests