libc.obj : added a very simple example of working with futexes
git-svn-id: svn://kolibrios.org@9867 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
92e48c928c
commit
a7f779193d
@ -5,7 +5,8 @@ KPACK = kpack
|
||||
CFLAGS = -I../include -B../../bin -I../../../../../../contrib/sdk/sources/SDL-1.2.2_newlib/include
|
||||
LIBS = -lbox_lib -lshell -lSDL -lsound -lnetwork -lrasterworks -limg -ldialog -lmsgbox
|
||||
|
||||
BIN = stdio_test.kex \
|
||||
BIN = \
|
||||
stdio_test.kex \
|
||||
basic_gui.kex \
|
||||
http_tcp_demo.kex \
|
||||
math_test.kex \
|
||||
@ -25,7 +26,8 @@ BIN = stdio_test.kex \
|
||||
shell_test.kex \
|
||||
libc_test.kex \
|
||||
pipe.kex \
|
||||
defgen.kex
|
||||
defgen.kex \
|
||||
futex.kex
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
|
@ -22,5 +22,6 @@ cp clayer/logo.png /tmp0/1/tcc_samples/logo.png
|
||||
../tcc libc_test.c -o /tmp0/1/tcc_samples/libc_test
|
||||
../tcc defgen.c -o /tmp0/1/tcc_samples/defgen
|
||||
../tcc pipe.c -o /tmp0/1/tcc_samples/pipe
|
||||
../tcc futex.c -o /tmp0/1/tcc_samples/futex
|
||||
"/sys/File managers/Eolite" /tmp0/1/tcc_samples
|
||||
exit
|
||||
|
57
programs/develop/ktcc/trunk/libc.obj/samples/futex.c
Normal file
57
programs/develop/ktcc/trunk/libc.obj/samples/futex.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include <sys/ksys.h>
|
||||
|
||||
/* Very simple example of working with futexes in Kolibri OS.
|
||||
* Author turbocat (Maxim Logaev).
|
||||
* Thanks to Vitaly Krylov for help.
|
||||
*
|
||||
* The result of the program execution can be seen in the debug board.
|
||||
*/
|
||||
|
||||
#define TH_STACK_SIZE 1024
|
||||
#define TH_LOCK 1
|
||||
#define TH_UNLOCK 0
|
||||
|
||||
uint8_t th_stack[TH_STACK_SIZE];
|
||||
|
||||
int glob_var = 0;
|
||||
int th_lock = TH_UNLOCK;
|
||||
uint32_t futex = 0;
|
||||
|
||||
void th_main(void)
|
||||
{
|
||||
_ksys_debug_puts("Child thread start\n");
|
||||
_ksys_futex_wait(futex, TH_LOCK, 0);
|
||||
glob_var = 99;
|
||||
_ksys_debug_puts("Child thread end\n");
|
||||
_ksys_exit();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
_ksys_debug_puts("Parrent thread start");
|
||||
futex = _ksys_futex_create(&th_lock);
|
||||
th_lock = TH_LOCK;
|
||||
|
||||
if (_ksys_create_thread(th_main, th_stack) == -1) {
|
||||
_ksys_debug_puts("Unable to create a new thread!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
glob_var = 88;
|
||||
_ksys_thread_yield();
|
||||
|
||||
_ksys_delay(100);
|
||||
|
||||
if (glob_var == 88) {
|
||||
_ksys_debug_puts("Futex test OK :)\n");
|
||||
} else {
|
||||
_ksys_debug_puts("Futex test FAIL :(\n");
|
||||
}
|
||||
|
||||
th_lock = TH_UNLOCK;
|
||||
_ksys_futex_wake(futex, 1);
|
||||
|
||||
_ksys_futex_destroy(futex);
|
||||
_ksys_debug_puts("Parrent thread end");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user