Test payloads
*/
+#define __int(ptr) ((int)(unsigned long)(ptr))
+#define __ptr(ptr) ((void*)(unsigned long)(ptr))
+
static void*
__print_and_sleep_randsec(void* value)
{
pthread_t tid = pthread_self();
- printf("thread %d: gets number %d\n", tid, (int)value);
+ printf("thread %d: gets number %d\n", tid, __int(value));
int fd = open("/dev/rand", O_RDONLY | O_DIRECT);
if (fd < 0) {
__print_and_sleep_seq(void* value)
{
pthread_t tid = pthread_self();
- printf("thread %d: gets number %d\n", tid, (int)value);
+ printf("thread %d: gets number %d\n", tid, __int(value));
- int second = (int)value % 30;
+ int second = __int(value) % 30;
printf("thread %d: going to sleep %ds\n", tid, second);
sleep(second);
__print_and_sleep(void* value)
{
pthread_t tid = pthread_self();
- printf("thread %d: gets number %d\n", tid, (int)value);
+ printf("thread %d: gets number %d\n", tid, __int(value));
sleep(1);
printf("thread %d: exit\n", tid);
int err;
pthread_t created;
for (int i = 0; i < amount; i++) {
- err = pthread_create(&created, NULL, fn, (void*)i);
+ err = pthread_create(&created, NULL, fn, __ptr(i));
if (err) {
printf("unable to create thread: %d\n", err);
continue;
void* v;
for (int i = 0; i < param; i++)
{
- err = pthread_create(&created, NULL, __print_and_sleep, (void*)i);
+ err = pthread_create(&created, NULL, __print_and_sleep, __ptr(i));
if (err) {
printf("unable to create thread: %d\n", err);
}
do { \
printf("** [%s] test start\n", note); \
pthread_test_##testn(__VA_ARGS__); \
- printf("** [%s] test passed\n"); \
+ printf("** [%s] test passed\n", note); \
} while (0)
int main()