@@ -144,6 +144,44 @@ ZTEST(key, test_correct_key_is_deleted)
144
144
}
145
145
}
146
146
147
+ static void * setspecific_thread (void * count )
148
+ {
149
+ int value = 42 ;
150
+ int * alloc_count = count ;
151
+
152
+ while (1 ) {
153
+ pthread_key_t key ;
154
+
155
+ zassert_ok (pthread_key_create (& key , NULL ), "failed to create key" );
156
+ if (pthread_setspecific (key , & value ) == ENOMEM ) {
157
+ break ;
158
+ };
159
+ * alloc_count += 1 ;
160
+ }
161
+
162
+ return NULL ;
163
+ }
164
+
165
+ ZTEST (key , test_thread_specific_data_deallocation )
166
+ {
167
+ pthread_t thread ;
168
+ static int alloc_count_t0 ;
169
+ static int alloc_count_t1 ;
170
+
171
+ zassert_ok (pthread_create (& thread , NULL , setspecific_thread , & alloc_count_t0 ),
172
+ "attempt to create thread failed" );
173
+ zassert_ok (pthread_join (thread , NULL ), "failed to join thread" );
174
+ printk ("first thread allocated %d keys" , alloc_count_t0 );
175
+
176
+ zassert_ok (pthread_create (& thread , NULL , setspecific_thread , & alloc_count_t1 ),
177
+ "attempt to create thread failed" );
178
+ zassert_ok (pthread_join (thread , NULL ), "failed to join thread" );
179
+ printk ("second thread allocated %d keys" , alloc_count_t1 );
180
+
181
+ zassert_equal (alloc_count_t0 , alloc_count_t1 ,
182
+ "failed to deallocate thread specific data" );
183
+ }
184
+
147
185
static void before (void * arg )
148
186
{
149
187
ARG_UNUSED (arg );
0 commit comments