-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brian Zhao
committed
Oct 28, 2023
1 parent
0656048
commit 7d8e300
Showing
7 changed files
with
99 additions
and
77 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
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
Submodule wasm-micro-runtime
updated
337 files
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
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,48 +1,43 @@ | ||
/* | ||
* Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
* Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
|
||
#define MAX_NUM_THREADS 2 | ||
#define NUM_ITER 1000 | ||
|
||
int g_count = 0; | ||
|
||
static void * | ||
thread(void *arg) | ||
{ | ||
for (int i = 0; i < NUM_ITER; i++) { | ||
__atomic_fetch_add(&g_count, 1, __ATOMIC_SEQ_CST); | ||
} | ||
printf("%d\n", g_count); | ||
return NULL; | ||
static void *thread(void *arg) { | ||
for (int i = 0; i < NUM_ITER; i++) { | ||
__atomic_fetch_add(&g_count, 1, __ATOMIC_SEQ_CST); | ||
} | ||
printf("%d\n", g_count); | ||
return NULL; | ||
} | ||
|
||
int | ||
main(int argc, char **argv) | ||
{ | ||
pthread_t tids[MAX_NUM_THREADS]; | ||
|
||
for (int i = 0; i < MAX_NUM_THREADS; i++) { | ||
if (pthread_create(&tids[i], NULL, thread, NULL) != 0) { | ||
printf("Thread creation failed\n"); | ||
} | ||
} | ||
|
||
for (int i = 0; i < MAX_NUM_THREADS; i++) { | ||
if (pthread_join(tids[i], NULL) != 0) { | ||
printf("Thread join failed\n"); | ||
} | ||
} | ||
|
||
printf("Value of counter after update: %d (expected=%d)\n", g_count, | ||
MAX_NUM_THREADS * NUM_ITER); | ||
if (g_count != MAX_NUM_THREADS * NUM_ITER) { | ||
__builtin_trap(); | ||
} | ||
|
||
return -1; | ||
} | ||
int main(int argc, char **argv) { | ||
pthread_t tids[MAX_NUM_THREADS]; | ||
|
||
for (int i = 0; i < MAX_NUM_THREADS; i++) { | ||
if (pthread_create(&tids[i], NULL, thread, NULL) != 0) { | ||
printf("Thread creation failed\n"); | ||
} | ||
} | ||
|
||
for (int i = 0; i < MAX_NUM_THREADS; i++) { | ||
if (pthread_join(tids[i], NULL) != 0) { | ||
printf("Thread join failed\n"); | ||
} | ||
} | ||
|
||
printf("Value of counter after update: %d (expected=%d)\n", g_count, MAX_NUM_THREADS * NUM_ITER); | ||
if (g_count != MAX_NUM_THREADS * NUM_ITER) { | ||
__builtin_trap(); | ||
} | ||
|
||
return -1; | ||
} |