RE: Bug in pth_key_delete() ?

2004-10-15 Thread Vinu V


>Well, the main problem is that a call to pth_key_delete() is only
>valid after clearing (with "pth_key_setdata(..., NULL)") the data
>corresponding to this key in *all* threads. Just clearing the key 
>in the *current* thread is not sufficient.

I believe the pth_key_***()  APIs are used for "thread 
local storage". So does it really matter whats the data value 
for this key in other threads ?. Please correct me If I am wrong.

I think it would be great if the documentation for Pth 
 
could explain something about what all the application 
should do before destroying a private key.

> Additionally to clearing the data, the corresponding destructor
>has to be called first, too.

I think pth_key_delete() is used to destroy only
a *single key* and not to free the complete memory allocated for 
storing the private data values for a thread. So is it required to call
the destructor function from a pth_key_delete () ?


>The question just is: should pth_key_delete() return with e.g. EBUSY
>in case any thread still uses data associated with the key or should
>it instead automatically free all the data associated with it in all
>threads. I personally think pth_key_delete() should return EBUSY. 
>Any objections?

I think the pth_key_delete() should be a little more intelligent
rather than asking the application to handle such conditions.  Or does 
current implementation of these APIs restricts *a thread* from 
freeing only a specific key. If that is the case then I think the 
pth_key_delete() should return EBUSY.


PS: I am not able see the mails posted after "10/08/2004" in 
the Pth mailing list archives.
.
Does anyone else in this group is facing this problem ?


Regards,
Vinu V

__
GNU Portable Threads (Pth)http://www.gnu.org/software/pth/
Development Site  http://www.ossp.org/pkg/lib/pth/
Distribution Files  ftp://ftp.gnu.org/gnu/pth/
Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager (Majordomo)   [EMAIL PROTECTED]
-
Disclaimer
-

"This message(including attachment if any)is confidential and may be privileged.Before 
opening attachments please check them
for viruses and defects.MindTree Consulting Private Limited (MindTree)will not be 
responsible for any viruses or defects or
any forwarded attachments emanating either from within MindTree or outside.If you have 
received this message by mistake please notify the sender by return  e-mail and delete 
this message from your system. Any unauthorized use or dissemination of this message 
in whole or in part is strictly prohibited.  Please note that e-mails are susceptible 
to change and MindTree shall not be liable for any improper, untimely or incomplete 
transmission."

-

Re: Bug in pth_key_delete() ?

2004-10-14 Thread Ralf S. Engelschall
On Thu, Oct 14, 2004, Vinu V wrote:

> I am using the pth_key_* APIs in my program and I came across a point
> where the Pth library is crashing. Don't know whether this is a bug
> with Pth or with my program.
> This is what I have done.
>
> int taskVar
> main ()
> {
>
>  int retValue;
>  pth_mutex_t mutex;
>  pth_mutex_t cond;
>
>  pth_spawn(PTH_ATTR_DEFAULT, task1, NULL);
>
>  pth_mutex_init(&mutex);
>  pth_cond_init(&cond);
>
>  pth_key_create(&taskVar, NULL);
>  pth_key_setdata(taskVar, (int *)123);
>  retValue = (int)pth_key_getdata(taskVar);
>  retValue = pth_key_delete(taskVar);
>
>  pth_mutex_acquire(&mutex, 0, NULL);
>  pth_cond_await(&cond, &mutex, NULL);
>  pth_mutex_release(&mutex);
>
> } /* End of main */
>
> void *task1(void *arg)
> {
>   pth_mutex_acquire(&mutex, 0, NULL);
>   pth_cond_notify(&cond, 0);
>   pth_mutex_release(&mutex);
> }
>
> Here the program crashes at pth_cond_await() in main.
> When I comment the pth_key_delete() in main(), then this works perfectly.
>
> I think this is beacause of a bug in pth_key_delete().
>
> int pth_key_delete(pth_key_t key)
> {
> if (key >= PTH_KEY_MAX)
> return pth_error(FALSE, EINVAL);
> if (!pth_keytab[key].used)
> return pth_error(FALSE, EINVAL);
> pth_keytab[key].used = FALSE;
> return TRUE;
> }
>
> This function marks the "used" field of the specified key( in this
> example this is the index 0 of pth_keytab[] array) as FALSE. But it
> is not making the data pointer for this key as NULL. Hence the data
> pointer still contains the value 123.
>
> Now the pth_mutex_acquire internally uses the pth_key_getdata(), which
> returns the a a value of 123 which is invalid value for the mutex
> event and it crashes when it tries to manipulate this event data.
>
> Possible FIX.
> -
> This problem got solved when I cleared the data_value pointer within the
> pth_key_delete() function.
>
> int pth_key_delete(pth_key_t key)
> {
> if (key >= PTH_KEY_MAX)
> return pth_error(FALSE, EINVAL);
> if (!pth_keytab[key].used)
> return pth_error(FALSE, EINVAL);
>
> pth_keytab[key].used = FALSE;
> pth_current->data_value[key] =(void *)NULL;
>
> return TRUE;
> }
>
> Please correct me if I am doing anything wrong here ...

Well, the main problem is that a call to pth_key_delete() is only
valid after clearing (with "pth_key_setdata(..., NULL)") the data
corresponding to this key in *all* threads. Just clearing the key in the
*current* thread is not sufficient. Additionally to clearing the data,
the corresponding destructor has to be called first, too.

The question just is: should pth_key_delete() return with e.g. EBUSY
in case any thread still uses data associated with the key or should
it instead automatically free all the data associated with it in all
threads. I personally think pth_key_delete() should return EBUSY. Any
objections?
   Ralf S. Engelschall
   [EMAIL PROTECTED]
   www.engelschall.com

__
GNU Portable Threads (Pth)http://www.gnu.org/software/pth/
Development Site  http://www.ossp.org/pkg/lib/pth/
Distribution Files  ftp://ftp.gnu.org/gnu/pth/
Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager (Majordomo)   [EMAIL PROTECTED]