Skip to content

Commit 3aa6e16

Browse files
tautschnigDaniel Kroening
authored and
Daniel Kroening
committed
Disable support for pthread_keyt destructors
They are too expensive due to extensive shared-variable use.
1 parent 6ff80c4 commit 3aa6e16

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/ansi-c/library/pthread_lib.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,17 @@ inline void pthread_exit(void *value_ptr)
301301
{
302302
__CPROVER_HIDE:;
303303
if(value_ptr!=0) (void)*(char*)value_ptr;
304+
#if 0
305+
// Destructor support is disabled as it is too expensive due to its extensive
306+
// use of shared variables.
304307
for(unsigned long i = 0; i < __CPROVER_next_thread_key; ++i)
305308
{
306309
const void *key = __CPROVER_thread_keys[i];
307310
__CPROVER_thread_keys[i] = 0;
308311
if(__CPROVER_thread_key_dtors[i] && key)
309312
__CPROVER_thread_key_dtors[i](key);
310313
}
314+
#endif
311315
__CPROVER_threads_exited[__CPROVER_thread_id]=1;
312316
__CPROVER_assume(0);
313317
}
@@ -541,16 +545,24 @@ extern __CPROVER_thread_local unsigned long __CPROVER_next_thread_key;
541545

542546
inline void __spawned_thread(
543547
unsigned long this_thread_id,
548+
#if 0
549+
// Destructor support is disabled as it is too expensive due to its extensive
550+
// use of shared variables.
544551
void (**thread_key_dtors)(void *),
552+
#endif
545553
unsigned long next_thread_key,
546554
void *(*start_routine)(void *),
547555
void *arg)
548556
{
549557
__CPROVER_HIDE:;
550558
__CPROVER_thread_id = this_thread_id;
551559
__CPROVER_next_thread_key = next_thread_key;
560+
#if 0
561+
// Destructor support is disabled as it is too expensive due to its extensive
562+
// use of shared variables.
552563
for(unsigned long i = 0; i < __CPROVER_next_thread_key; ++i)
553564
__CPROVER_thread_key_dtors[i] = thread_key_dtors[i];
565+
#endif
554566
#ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
555567
// Clear all locked mutexes; locking must happen in same thread.
556568
__CPROVER_clear_must(0, "mutex-locked");
@@ -566,13 +578,17 @@ __CPROVER_HIDE:;
566578
"RRcumul",
567579
"RWcumul",
568580
"WRcumul");
581+
#if 0
582+
// Destructor support is disabled as it is too expensive due to its extensive
583+
// use of shared variables.
569584
for(unsigned long i = 0; i < __CPROVER_next_thread_key; ++i)
570585
{
571586
const void *key = __CPROVER_thread_keys[i];
572587
__CPROVER_thread_keys[i] = 0;
573588
if(__CPROVER_thread_key_dtors[i] && key)
574589
__CPROVER_thread_key_dtors[i](key);
575590
}
591+
#endif
576592
__CPROVER_threads_exited[this_thread_id] = 1;
577593
}
578594

@@ -598,11 +614,23 @@ inline int pthread_create(
598614
if(attr) (void)*attr;
599615

600616
unsigned long next_thread_key = __CPROVER_next_thread_key;
617+
#if 0
618+
// Destructor support is disabled as it is too expensive due to its extensive
619+
// use of shared variables.
601620
void (**thread_key_dtors)(void *) = __CPROVER_thread_key_dtors;
621+
#endif
602622

603623
__CPROVER_ASYNC_1:
604624
__spawned_thread(
605-
this_thread_id, thread_key_dtors, next_thread_key, start_routine, arg);
625+
this_thread_id,
626+
#if 0
627+
// Destructor support is disabled as it is too expensive due to its
628+
// extensive use of shared variables.
629+
thread_key_dtors,
630+
#endif
631+
next_thread_key,
632+
start_routine,
633+
arg);
606634

607635
return 0;
608636
}
@@ -895,7 +923,13 @@ inline int pthread_key_create(pthread_key_t *key, void (*destructor)(void *))
895923
{
896924
__CPROVER_HIDE:;
897925
__CPROVER_thread_keys[__CPROVER_next_thread_key] = 0;
926+
#if 0
927+
// Destructor support is disabled as it is too expensive due to its extensive
928+
// use of shared variables.
898929
__CPROVER_thread_key_dtors[__CPROVER_next_thread_key] = destructor;
930+
#else
931+
__CPROVER_precondition(destructor == 0, "destructors are not yet supported");
932+
#endif
899933
*key = __CPROVER_next_thread_key++;
900934
return 0;
901935
}

0 commit comments

Comments
 (0)