About thread.

Dec 12, 2009 at 5:02pm

About thread.

Hello Maxers,

I have :

void myobject_bang (t_myobject *x) {
do_something_on_my_data (x) ;
}

Overdrive is ON, two bangs are coming, first in main thread , second in timer thread :
is 2nd bang kill do_something from the first ?
is both do_something are done same time :-( ?
is first do_something stop while second do it, and continue after ?

And if i have too :
void myobject_toto (t_myobject *x) {
do_the_same_on_my_data (x) ;
}

What’s happen with toto vs bang ?

#47171
Dec 19, 2009 at 12:38pm

Hello maxers,

so i find responses in Andrew Tanenbaum’s book …
but i have another question now ;
is it possible to make something like that :

if (!x->lock) {
ATOMIC_INCREMENT (&x->lock) ;
do_something (x) ;
ATOMIC_DECREMENT (&x->lock) ;
}

i have feeling that’s not good, as concurrent threads will test (x->lock) before increment, but is there a best way to achieve this kind of stuff ?

That ?

k = ATOMIC_INCREMENT (&x->lock) ;
if ( k == 1) {
do_something (x) ;
ATOMIC_DECREMENT (&x->lock) ;
}
else {
ATOMIC_DECREMENT (&x->lock) ;
}

This works : critical_enter (0) ; do_something (x) ; critical_exit (0) ; but it seems it’s not good to put so much code in critical area.

Salutations.

#169586
Dec 19, 2009 at 1:41pm

The ‘collect’ example in the SDK shows how to make your own mutex so that you aren’t adding so much stuff to the global critical region with critical_enter(0).

HTH

#169587
Dec 19, 2009 at 4:50pm

Hello Timothy,

Thanks, i’ll have a look on “collect” …
I did few test with ATOMIC_INCREMENT stuff i post before, and it seems it’s work nice.
I’ll try both way and compare.

#169588
Dec 20, 2009 at 4:57pm

Hello maxers,

ok so : systhread_mutex_trylock () do what i wanted to do.

“Muchas gracias” again Timothy.

#169589

You must be logged in to reply to this topic.