STM: Simple program locks up when trying to commit a transaction

STM: Simple program locks up when trying to commit a transaction

Hi -

The following simple program seems to lock up after trying to commit the transaction of thread_body_2 (you might see some transactions commited before locking up) Debugging with gdb reveals that the thread
blocks after trying to commit the transaction; STM goes through
STMTxnCommit -> commitCanComplete -> platformThreadYield ->
sched_yield

Any ideas why?

#include
#include
#include

#define NUM_THREADS 2 /* should be an even number */

void* thread_body_1(void* arg)
{
__tm_atomic {
while(1);
}
return NULL;
}

void* thread_body_2(void* arg)
{
int dummy, i;

while (1) {
i++;
printf("BEGIN %d
", i);
__tm_atomic {
dummy = 0;
}
printf("COMMIT %d
", i);
}
return NULL;
}

int main(int argc, char* argv[])
{
int i;
pthread_t *threads;
int tids[NUM_THREADS];

threads = (pthread_t*) calloc(NUM_THREADS, sizeof(pthread_t));
pthread_create(&threads[0], NULL, thread_body_1, NULL);
pthread_create(&threads[1], NULL, thread_body_2, NULL);

for (i = 0; i < NUM_THREADS; ++i) {
pthread_join(threads[i], NULL);
}
}

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

What semantics are you expecting from transactions?

If you consider them to have the same semantics as a single global lock, then this code clearly deadlocks, so it is no big surprise that it can also deadlock with TM...

Leave a Comment

Please sign in to add a comment. Not a member? Join today