patacongo commented on a change in pull request #3626:
URL: https://github.com/apache/incubator-nuttx/pull/3626#discussion_r623128090



##########
File path: libs/libc/pthread/pthread_exit.c
##########
@@ -0,0 +1,72 @@
+/****************************************************************************
+ * libs/libc/pthread/pthread_exit.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <debug.h>
+#include <sched.h>
+
+#include <nuttx/pthread.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pthread_exit
+ *
+ * Description:
+ *   Terminate execution of a thread started with pthread_create.
+ *
+ * Input Parameters:
+ *   exit_valie
+ *
+ * Returned Value:
+ *   None
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+void pthread_exit(FAR void *exit_value)
+{
+#ifdef CONFIG_PTHREAD_CLEANUP
+  int cnt;
+  struct pthread_cleanup_s cleanup[CONFIG_PTHREAD_CLEANUP_STACKSIZE];
+  cnt = pthread_cleanup_poplist(cleanup);
+
+  sched_lock();
+  while (cnt-- > 0)
+    {
+      struct pthread_cleanup_s cp = cleanup[cnt];
+      if (cp.pc_cleaner)
+        cp.pc_cleaner(cp.pc_arg);
+    }
+
+  sched_unlock();
+#endif
+

Review comment:
       > Yes, I had implemented a version of tls data destructors
   
   This is not in this PR, however.  I was referring to the data destructor in 
pthread_key_create().
   
       int pthread_key_create(pthread_key_t *key, void (*destructor)(void*));
   
   See 
https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_key_create.html
 :
   
   "An optional destructor function may be associated with each key value. At 
thread exit, if a key value has a non-NULL destructor pointer, and the thread 
has a non-NULL value associated with that key, the value of the key is set to 
NULL, and then the function pointed to is called with the previously associated 
value as its sole argument. The order of destructor calls is unspecified if 
more than one destructor exists for a thread when it exits.
   
   "If, after all the destructors have been called for all non-NULL values with 
associated destructors, there are still some non-NULL values with associated 
destructors, then the process is repeated. If, after at least 
{PTHREAD_DESTRUCTOR_ITERATIONS} iterations of destructor calls for outstanding 
non-NULL values, there are still some non-NULL values with associated 
destructors, implementations may stop calling destructors, or they may continue 
calling destructors until no non-NULL values with associated destructors exist, 
even though this might result in an infinite loop."
   
   This would effect TLS data format where the destructors would be stored, 
pthread_key_create() which would need to save the destructor function pointers 
(in TLS), and pthread_exit() that would call the pthread data destructors,
   
   This is separate functionality from the changes of this PR but is part of 
the longer term motivation for moving pthread_exit into user space.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to