-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multi-threaded simultaneous get_session_key test.
- Loading branch information
Showing
2 changed files
with
15 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
/** | ||
* @file multi_thread_get_session_key_test.c | ||
* @author your name ([email protected]) | ||
* @brief Test get_session_key() in multiple threads. | ||
* This tests if get_session_key() can be called in multiple threads without | ||
* mutex locks. However, this test nondeterministically fails. | ||
* @copyright Copyright (c) 2025 | ||
* | ||
*/ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
@@ -8,26 +17,27 @@ | |
void *send_request(void *SST_ctx) { | ||
SST_ctx_t *ctx = (SST_ctx_t *)SST_ctx; | ||
for (int i = 0; i < 1; i++) { | ||
// If there is no mutex_lock, this test fails. | ||
// pthread_mutex_lock(&ctx->mutex); | ||
session_key_list_t *s_key_list; | ||
s_key_list = get_session_key(ctx, s_key_list); | ||
// pthread_mutex_unlock(&ctx->mutex); | ||
// free_session_key_list_t(s_key_list); | ||
free_session_key_list_t(s_key_list); | ||
} | ||
return NULL; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
char *config_path = argv[1]; | ||
SST_ctx_t *ctx = init_SST(config_path); | ||
|
||
// Request one session key to just ensure got distribution key. | ||
// Request one session key to just ensure getting the distribution key. | ||
session_key_list_t *s_key_list = get_session_key(ctx, NULL); | ||
sleep(2); | ||
int num_threads = 5; | ||
pthread_t thread[num_threads]; | ||
for (int i = 0; i < num_threads; i++) { | ||
pthread_create(&thread[i], NULL, &send_request, (void *)ctx); | ||
// sleep(1); // If this exits, this doesn't fail. | ||
} | ||
for (int i = 0; i < 100; i++) { | ||
pthread_join(thread[i], NULL); | ||
|