On 5/4/12, niXman <i.nix...@gmail.com> wrote:
> Hi,
>
> This simple code change the last error which sometimes is not allowed:
>> #include <pthread.h>
>> int main() {
>>      SetLastError(33);
>>      pthread_getspecific(0);
>>      return GetLastError();
>> }
>>
>> $ gcc test.c -otest
>> $ ./test; echo $?
>> $ 0
>
> Tell me please, have anyone faced with this problem? Maybe in the
> mailing list there is a subject about this?
> The question is whether will be correct the changing of
> winpthreads-api this way?:
>> void* pthread_getspecific(pthread_key_t key) {
>>    DWORD _last_error=GetLastError();
>>    ...
>>    ...some code...
>>    ...
>>    SetLastError(_last_error);
>> }
>
> Indeed, logically, the implementation of winpthreads should not have
> no effect on GetLastError/SetLastError?
>

Such preservation is indeed present in pthreads-w32 version of
pthread_getspecific(), so should we add the following:

--- thread.c~
+++ thread.c
@@ -748,10 +748,12 @@ void *
 pthread_getspecific (pthread_key_t key)
 {
   void *r;
+  DWORD lasterror = GetLastError ();
   _pthread_v *t = __pthread_self_lite ();
   _spin_lite_lock (&t->spin_keys);
   r = (key >= t->keymax || t->keyval_set[key] == 0 ? NULL : t->keyval[key]);
   _spin_lite_unlock (&t->spin_keys);
+  SetLastError (lasterror);
   return r;
 }


Kai?


> Thanks!
>
>
> --
> Regards,
>   niXman

--
O.S.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to