In C, the longest palindromic subsequence multithread exists


Joined
Jun 29, 2022
Messages
10
Reaction score
0
I'm learning how to multithread in C and figured the longest palindromic subsequence issue would be a good place to start.

To get the solution, we run two threads and compare their results. One thread is concerned with "odd" subsequences, whereas the other is concerned with "even" ones.
Code:
struct str* s0 = malloc(sizeof(struct str));
  struct str* s1 = malloc(sizeof(struct str));
  s0->seq = (char*)seq0;
  s1->seq = (char*)seq0;
  s0->len = len;
  s1->len = len;

  pthread_t t0;
  pthread_t t1;
  int* res0;
  int* res1;
  if (pthread_create(&t0, NULL, &odd, s0)!=0){
    return 0;
  }
  if (pthread_create(&t1, NULL, &even, s1)!=0){
    return 00;
  }
  if(pthread_join(t0, (void**)&res0)!=0){
    return 1;
  }
  if(pthread_join(t1, (void**)&res1)!=0){
    return 11;
  }

  if(*res0 > *res1){
    printf("%d\n", *res0);
  }else{
    printf("%d\n", *res1);
  }

  free(s0);
  free(s1);
  return 0;
}
Although the code appears to function, I'm curious about where in the application I should look for multi-threading issues. As I'm learning from this source, it's all new to me, thus I only need to know which portions may be prone to the troubles that multi-threading introduces.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top