mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 22:52:45 +01:00
7a1c099e7b
Fixed compilation errors. Mostly DEBUG/printf formatting and void pointer casting. Other changes are: * net/gnrc_sixlowpan_frag_*: Generalized packet size calculation * cpu/native_backtrace: Reduced required backtrace size to 3 for 64-bit * periph/flashpage: Simplified test * unittests/tests-pktbuf: Generalized alignment * sys/architecture: Extended test for 64-bit
83 lines
1.7 KiB
C
83 lines
1.7 KiB
C
/*
|
|
* Copyright (C) 2014 Hamburg University of Applied Sciences
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
* directory for more details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup tests
|
|
* @{
|
|
*
|
|
* @file
|
|
* @brief pthread test application
|
|
*
|
|
* @author Raphael Hiesgen <raphael.hiesgen@haw-hamburg.de>
|
|
*
|
|
* @}
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <pthread.h>
|
|
|
|
#define NUM_THREADS 12
|
|
|
|
#define FACTORIAL_EXPECTED (479001600UL)
|
|
|
|
pthread_t ths[NUM_THREADS];
|
|
|
|
pthread_mutex_t mtx;
|
|
volatile uint32_t storage = 1;
|
|
|
|
void *run(void *parameter)
|
|
{
|
|
int arg = (intptr_t) parameter;
|
|
printf("My arg: %d\n", arg);
|
|
|
|
int err = pthread_mutex_lock(&mtx);
|
|
|
|
if (err != 0) {
|
|
printf("[!!!] pthread_mutex_lock failed with %d\n", err);
|
|
return NULL;
|
|
}
|
|
|
|
storage *= arg;
|
|
printf("val = %"PRIu32"\n", storage);
|
|
pthread_mutex_unlock(&mtx);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
puts("START");
|
|
pthread_attr_t th_attr;
|
|
pthread_attr_init(&th_attr);
|
|
pthread_mutex_init(&mtx, NULL);
|
|
|
|
for (intptr_t i = 0; i < NUM_THREADS; ++i) {
|
|
printf("Creating thread with arg %" PRIdPTR "\n", (i + 1));
|
|
pthread_create(&ths[i], &th_attr, run, (void *)(i + 1));
|
|
}
|
|
|
|
for (int i = 0; i < NUM_THREADS; ++i) {
|
|
printf("join thread %d\n", (i + 1));
|
|
pthread_join(ths[i], NULL);
|
|
}
|
|
|
|
printf("Factorial: %"PRIu32"\n", storage);
|
|
|
|
pthread_mutex_destroy(&mtx);
|
|
pthread_attr_destroy(&th_attr);
|
|
|
|
if (storage == FACTORIAL_EXPECTED) {
|
|
puts("SUCCESS");
|
|
}
|
|
else {
|
|
puts("FAILURE: Error, expected: 12!= 479001600.");
|
|
}
|
|
|
|
return 0;
|
|
}
|