mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
Comment on gem5's broken GDB on secondary core
Try to assert on all C programs if thread creation failed. C++ already throws by default.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* https://cirosantilli.com/linux-kernel-module-cheat#atomic-c */
|
||||
|
||||
#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
|
||||
#include <assert.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdio.h>
|
||||
#include <threads.h>
|
||||
@@ -36,9 +37,9 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
threads = malloc(sizeof(thrd_t) * nthreads);
|
||||
for(size_t i = 0; i < nthreads; ++i)
|
||||
thrd_create(threads + i, my_thread_main, &niters);
|
||||
assert(thrd_create(threads + i, my_thread_main, &niters) == thrd_success);
|
||||
for(size_t i = 0; i < nthreads; ++i)
|
||||
thrd_join(threads[i], NULL);
|
||||
assert(thrd_join(threads[i], NULL) == thrd_success);
|
||||
free(threads);
|
||||
printf("atomic %u\n", acnt);
|
||||
printf("non-atomic %u\n", cnt);
|
||||
|
||||
@@ -43,8 +43,8 @@ int main(void) {
|
||||
enum NUM_THREADS {NUM_THREADS = 2};
|
||||
pthread_t threads[NUM_THREADS];
|
||||
int thread_args[NUM_THREADS];
|
||||
pthread_create(&threads[0], NULL, main_thread_0, (void*)&thread_args[0]);
|
||||
pthread_create(&threads[1], NULL, main_thread_1, (void*)&thread_args[1]);
|
||||
assert(!pthread_create(&threads[0], NULL, main_thread_0, (void*)&thread_args[0]));
|
||||
assert(!pthread_create(&threads[1], NULL, main_thread_1, (void*)&thread_args[1]));
|
||||
pthread_join(threads[0], NULL);
|
||||
pthread_join(threads[1], NULL);
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -40,9 +40,9 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* Action */
|
||||
for (i = 0; i < nthreads; ++i)
|
||||
pthread_create(&threads[i], NULL, main_thread, &niters);
|
||||
assert(!pthread_create(&threads[i], NULL, main_thread, &niters));
|
||||
for (i = 0; i < nthreads; ++i)
|
||||
pthread_join(threads[i], NULL);
|
||||
assert(!pthread_join(threads[i], NULL));
|
||||
assert(global == nthreads * niters);
|
||||
|
||||
/* Cleanup. */
|
||||
|
||||
Reference in New Issue
Block a user