On Mon, 2008-08-25 at 14:03 +0530, Ankita Garg wrote:
> Hi,
>
> While the synchronization in the sched_football testcase under the
> realtime test suite is not erroneous, it can be enahnced and made more
> reliable by making use of pthread_barriers, like in other testcases.
> This patch adds the same.
>
> Testing done: Infinite iterations of the testcase run with this patch.
>
> Signed-off-by: Ankita Garg <[EMAIL PROTECTED]>
Thanks Ankita.
> Acked-by: Vernon Mauery <[EMAIL PROTECTED]>
Merged-By: Subrata Modak <[EMAIL PROTECTED]>
>
> Index:
> ltp-full-20080731/testcases/realtime/func/sched_football/sched_football.c
> ===================================================================
> ---
> ltp-full-20080731.orig/testcases/realtime/func/sched_football/sched_football.c
> 2008-08-25 13:55:23.000000000 +0530
> +++ ltp-full-20080731/testcases/realtime/func/sched_football/sched_football.c
> 2008-08-25 13:58:33.000000000 +0530
> @@ -73,12 +73,8 @@
> /* Here's the position of the ball */
> volatile int the_ball;
>
> -/* Keep track of who's on the field */
> -volatile int offense_count;
> -volatile int defense_count;
> -
> -/* simple mutex for our atomic increments */
> -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
> +/* pthread_barrier for synchronization */
> +pthread_barrier_t barrier;
>
> static int run_jvmsim=0;
> static int players_per_team = 0;
> @@ -121,9 +117,7 @@
> /* This is the defensive team. They're trying to block the offense */
> void *thread_defense(void* arg)
> {
> - pthread_mutex_lock(&mutex);
> - defense_count++;
> - pthread_mutex_unlock(&mutex);
> + pthread_barrier_wait(&barrier);
>
> /*keep the ball from being moved */
> while (1) {
> @@ -136,9 +130,7 @@
> /* This is the offensive team. They're trying to move the ball */
> void *thread_offense(void* arg)
> {
> - pthread_mutex_lock(&mutex);
> - offense_count++;
> - pthread_mutex_unlock(&mutex);
> + pthread_barrier_wait(&barrier);
>
> while (1) {
> the_ball++; /* move the ball ahead one yard */
> @@ -158,6 +150,8 @@
> now = start;
> the_ball = 0;
>
> + pthread_barrier_wait(&barrier);
> +
> /* Watch the game */
> while ((now.tv_sec - start.tv_sec) < game_length) {
> sleep(1);
> @@ -189,6 +183,11 @@
> printf("jvmsim disabled\n");
> }
>
> + if ((i = pthread_barrier_init(&barrier, NULL, players_per_team*2 + 1)))
> {
> + printf("pthread_barrier_init failed: %s\n", strerror(i));
> + exit(i);
> + }
> +
> printf("Running with: players_per_team=%d game_length=%d\n",
> players_per_team, game_length);
>
> @@ -202,8 +201,6 @@
> players_per_team, priority);
> for (i = 0; i < players_per_team; i++)
> create_fifo_thread(thread_offense, NULL, priority);
> - while (offense_count < players_per_team)
> - usleep(100);
>
> /* Start the defense */
> priority = 30;
> @@ -211,8 +208,6 @@
> players_per_team, priority);
> for (i = 0; i < players_per_team; i++)
> create_fifo_thread(thread_defense, NULL, priority);
> - while (defense_count < players_per_team)
> - usleep(100);
>
> /* Ok, everyone is on the field, bring out the ref */
> printf("Starting referee thread\n");
>
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list