|
From: Spiro T. <an-...@sp...> - 2009-10-30 22:28:32
|
Hello Shane,
* On Fri, Oct 30, 2009 at 05:24:12PM +0100 Shane O'Neill wrote:
> struct usb_dev_handle *Opendev(int vid, int pid)
> {
> struct usb_bus *bus;
> struct usb_device *dev;
> char message[100];
>
> for (bus=usb_get_busses();bus;bus=bus->next)
> {
> for (dev=bus->devices;dev;dev=dev->next)
> {
> if (dev->descriptor.idProduct == pid)
> {
> if (dev->descriptor.idVendor == vid)
> {
> current = usb_open(dev);
> sprintf(message, "Pointer = %08x.", current);
> MessagePopup(message, message);
> }
> }
> }
> }
> return current;
> }
>
> current is of data type "usb_dev_handle *current".
[...]
> There are plenty of occasions where the value of "current" as displayed
> by the message box is valid but the function still returns NULL.
>
> Is there something obviously wrong with what I'm doing here
Do you use "current" in different occassions? Do you have some race
condition: That is, two different code paths in two threads that both
write to "current"?
I would expect the problem in parallelism. Can't you define your
"current" variable locally, inside of the Opendev() function? That would
solve this problem.
HTH,
Spiro.
--
Spiro R. Trikaliotis http://opencbm.sf.net/
http://www.trikaliotis.net/ http://www.viceteam.org/
|