Skip to content

Commit 31b1fd4

Browse files
authored
[mono][tests] Fix deadlock in pinvoke detach test (#88855)
Without holding the condition mutex, the test is starting a new thread that is signaling us back. This means that the new thread could fail to signal us back, because there could be no waiters and the test would deadlock.
1 parent 36e32f8 commit 31b1fd4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/tests/Interop/MonoAPI/Native/mono-embedding-api-test/mono-embedding-api-test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,13 +1069,14 @@ mono_test_attach_invoke_block_foreign_thread (const char *assm_name, const char
10691069
pthread_mutex_init (&nm->deadlock_mutex, NULL);
10701070

10711071
pthread_mutex_lock (&nm->deadlock_mutex); // lock the mutex and never unlock it.
1072+
1073+
pthread_mutex_lock (&nm->coord_mutex);
10721074
pthread_t t;
10731075
int res = pthread_create (&t, NULL, invoke_block_foreign_thread, (void*)nm);
10741076
assert (res == 0);
10751077
/* wait for the foreign thread to finish calling the runtime before
10761078
* detaching it and returning
10771079
*/
1078-
pthread_mutex_lock (&nm->coord_mutex);
10791080
pthread_cond_wait (&nm->coord_cond, &nm->coord_mutex);
10801081
pthread_mutex_unlock (&nm->coord_mutex);
10811082
pthread_detach (t);

0 commit comments

Comments
 (0)