Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 9866 → Rev 9867

/programs/develop/ktcc/trunk/libc.obj/samples/Makefile
5,7 → 5,8
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
shell_test.kex \
libc_test.kex \
pipe.kex \
defgen.kex
defgen.kex \
futex.kex
all: $(BIN)
/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh
22,5 → 22,6
../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
/programs/develop/ktcc/trunk/libc.obj/samples/futex.c
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;
}