Subversion Repositories HelenOS

Rev

Rev 2479 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2479 Rev 4602
Line 25... Line 25...
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
30
#define THREADS 5
30
#define THREADS  20
-
 
31
#define DELAY    10
31
 
32
 
32
#include <atomic.h>
33
#include <atomic.h>
33
#include <thread.h>
34
#include <thread.h>
34
#include <stdio.h>
35
#include <stdio.h>
35
#include <unistd.h>
36
#include <unistd.h>
Line 40... Line 41...
40
static bool sh_quiet;
41
static bool sh_quiet;
41
 
42
 
42
static void threadtest(void *data)
43
static void threadtest(void *data)
43
{
44
{
44
    thread_detach(thread_get_id());
45
    thread_detach(thread_get_id());
45
 
46
   
46
    while (atomic_get(&finish)) {
47
    while (atomic_get(&finish))
47
        if (!sh_quiet)
-
 
48
            printf("%llu ", thread_get_id());
-
 
49
        usleep(100000);
48
        usleep(100000);
50
    }
49
   
51
    atomic_inc(&threads_finished);
50
    atomic_inc(&threads_finished);
52
}
51
}
53
 
52
 
54
char * test_thread1(bool quiet)
53
char *test_thread1(void)
55
{
54
{
56
    unsigned int i, total = 0;
55
    unsigned int i;
57
    sh_quiet = quiet;
56
    unsigned int total = 0;
58
   
57
   
59
    atomic_set(&finish, 1);
58
    atomic_set(&finish, 1);
60
    atomic_set(&threads_finished, 0);
59
    atomic_set(&threads_finished, 0);
61
 
60
   
-
 
61
    TPRINTF("Creating threads");
62
    for (i = 0; i < THREADS; i++) {  
62
    for (i = 0; i < THREADS; i++) {
63
        if (thread_create(threadtest, NULL, "threadtest", NULL) < 0) {
63
        if (thread_create(threadtest, NULL, "threadtest", NULL) < 0) {
64
            if (!quiet)
-
 
65
                printf("Could not create thread %d\n", i);
64
            TPRINTF("\nCould not create thread %u\n", i);
66
            break;
65
            break;
67
        }
66
        }
-
 
67
        TPRINTF(".");
68
        total++;
68
        total++;
69
    }
69
    }
70
   
70
   
71
    if (!quiet)
-
 
72
        printf("Running threads for 10 seconds...\n");
71
    TPRINTF("\nRunning threads for %u seconds...", DELAY);
73
    sleep(10);
72
    sleep(DELAY);
-
 
73
    TPRINTF("\n");
74
   
74
   
75
    atomic_set(&finish, 0);
75
    atomic_set(&finish, 0);
76
    while (atomic_get(&threads_finished) < total) {
76
    while (atomic_get(&threads_finished) < total) {
77
        if (!quiet)
-
 
78
            printf("Threads left: %d\n", total - atomic_get(&threads_finished));
77
        TPRINTF("Threads left: %u\n", total - atomic_get(&threads_finished));
79
        sleep(1);
78
        sleep(1);
80
    }
79
    }
81
   
80
   
82
    return NULL;
81
    return NULL;
83
}
82
}