2 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
13 #define THREAD_COUNT 20
17 read_thread(void* _data
)
19 port_id port
= (port_id
)_data
;
21 printf("[%ld] read port...\n", find_thread(NULL
));
24 ssize_t bytes
= port_buffer_size(port
);
25 printf("[%ld] buffer size %ld waiting\n", find_thread(NULL
), bytes
);
29 bytes
= read_port(port
, &code
, buffer
, sizeof(buffer
));
30 printf("[%ld] read port result (code %lx): %s\n", find_thread(NULL
),
31 code
, strerror(bytes
));
43 port_id port
= create_port(1, "test port");
44 printf("created port %ld\n", port
);
46 thread_id threads
[THREAD_COUNT
];
47 for (int32 i
= 0; i
< THREAD_COUNT
; i
++) {
48 threads
[i
] = spawn_thread(read_thread
, "read thread", B_NORMAL_PRIORITY
,
50 resume_thread(threads
[i
]);
53 printf("snooze for a bit, all threads should be waiting now.\n");
56 for (int32 i
= 0; i
< THREAD_COUNT
; i
++) {
57 size_t bytes
= 20 + i
;
59 memset(buffer
, 0x55, bytes
);
61 printf("send %ld bytes\n", bytes
);
62 write_port(port
, 0x42, buffer
, bytes
);
66 printf("waiting for threads to terminate\n");
67 for (int32 i
= 0; i
< THREAD_COUNT
; i
++) {
68 wait_for_thread(threads
[i
], NULL
);