Subversion Repositories HelenOS-historic

Rev

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

Rev 1129 Rev 1152
Line 37... Line 37...
37
#include <futex.h>
37
#include <futex.h>
38
 
38
 
39
int a;
39
int a;
40
atomic_t ftx;
40
atomic_t ftx;
41
 
41
 
42
int __thread tls_prom;
42
int __thread stage;
43
 
43
 
44
extern void utest(void *arg);
44
extern void utest(void *arg);
45
void utest(void *arg)
45
void utest(void *arg)
46
{
46
{
47
    printf("Uspace thread started.\n");
47
    printf("Uspace thread started.\n");
Line 255... Line 255...
255
    ipc_wait_for_call(&data, 0);
255
    ipc_wait_for_call(&data, 0);
256
}
256
}
257
 
257
 
258
static int ptest(void *arg)
258
static int ptest(void *arg)
259
{
259
{
260
    tls_prom = -1;
260
    stage = 1;
261
    printf("Pseudo thread stage%d.\n", -tls_prom);
261
    printf("Pseudo thread stage%d.\n", stage);
262
    tls_prom = -2;
262
    stage++;
263
    psthread_schedule_next();
263
    psthread_schedule_next();
264
    printf("Pseudo thread stage%d.\n", -tls_prom);
264
    printf("Pseudo thread stage%d.\n", stage);
265
    tls_prom = -3;
265
    stage++;
266
    psthread_schedule_next();
266
    psthread_schedule_next();
267
    printf("Pseudo thread stage%d\n", -tls_prom);
267
    printf("Pseudo thread stage%d.\n", stage);
268
    psthread_schedule_next();
268
    psthread_schedule_next();
-
 
269
    stage++;
269
    printf("Pseudo thread stage4.\n");
270
    printf("Pseudo thread stage%d.\n", stage);
270
    psthread_schedule_next();
271
    psthread_schedule_next();
271
    printf("Pseudo thread exiting.\n");
272
    printf("Pseudo thread exiting.\n");
272
    return 0;  
273
    return 0;  
273
}
274
}
274
 
275
 
Line 293... Line 294...
293
    if (futex_up(&ftx) < 0)
294
    if (futex_up(&ftx) < 0)
294
        printf("Futex failed.\n");
295
        printf("Futex failed.\n");
295
 
296
 
296
    if (futex_down(&ftx) < 0)
297
    if (futex_down(&ftx) < 0)
297
        printf("Futex failed.\n");
298
        printf("Futex failed.\n");
298
/*
299
 
299
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
300
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
300
        printf("Created thread tid=%d\n", tid);
301
        printf("Created thread tid=%d\n", tid);
301
    }
302
    }
302
 
303
 
303
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
304
    if ((tid = thread_create(utest, NULL, "utest")) != -1) {
304
        printf("Created thread tid=%d\n", tid);
305
        printf("Created thread tid=%d\n", tid);
305
    }
306
    }
306
*/
307
 
307
    int i;
308
    int i;
308
   
309
   
309
    for (i = 0; i < 50000000; i++)
310
    for (i = 0; i < 50000000; i++)
310
        ;
311
        ;
311
       
312
       
312
    if (futex_up(&ftx) < 0)
313
    if (futex_up(&ftx) < 0)
313
        printf("Futex failed.\n");
314
        printf("Futex failed.\n");
314
 
315
 
315
 
316
 
316
    printf("Creating pathread\n");
317
    printf("Creating pseudo thread.\n");
317
    tls_prom = 1;
318
    stage = 1;
318
    ptid = psthread_create(ptest, NULL);
319
    ptid = psthread_create(ptest, NULL);
319
    printf("Main thread stage%d\n",tls_prom);
320
    printf("Main thread stage%d.\n", stage);
320
    tls_prom = 2;
321
    stage++;
321
    psthread_schedule_next();;
322
    psthread_schedule_next();;
322
    printf("Main thread stage%d\n", tls_prom);
323
    printf("Main thread stage%d.\n", stage);
323
    tls_prom = 3;
324
    stage++;
324
    psthread_schedule_next();;
325
    psthread_schedule_next();;
325
    printf("Main thread stage%d\n", tls_prom);
326
    printf("Main thread stage%d.\n", stage);
326
 
327
 
327
    psthread_join(ptid);
328
    psthread_join(ptid);
328
 
329
 
329
    printf("Main thread exiting.\n");
330
    printf("Main thread exiting.\n");
330
    return 0;
331
    return 0;