Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question-> Given code: #define _XOPEN_SOURCE 600 #include #include #include #define MEM 64000 #include #include #include static ucontext_t ctx; static void conjecture(int len, void* options, int

Question->

image text in transcribed

Given code:

#define _XOPEN_SOURCE 600 #include #include #include #define MEM 64000 #include #include #include

static ucontext_t ctx;

static void conjecture(int len, void* options, int sz, void fn(void*)); // Create context and start traversal

void assert(bool b); // Restore context if condition fails

bool is_prime(int x) { for(int i = 2; i

bool is_lt_40(int x) { return x

int nested(int i) { assert(!is_prime(i)); return i * i; }

void app(void* c) { int* i = (int*)c; // printf("Trying %d ", *i); assert(is_lt_40(*i)); int x = nested(*i); printf("%d ", x); }

int main(void) { int mynums[] = {11, 23, 42, 39, 55}; // We have to ensure that conjecture lives in the bottom of the call stack. // If the conjecture frame is popped, we will never be able to rollback to it. conjecture(5, (void*) mynums, sizeof(int), &app); }

We would like to save and restore "contexts". The idea is to store a context (i.e, CPU registers) inside the conjecture method and when an assertion fails, restore the stored context and continue the process. Implement the following functions in the template provided: 1. static void conjecture(int len, void* options, int sz, void fn(void*)); 2. void assert(bool b); About the code: The main function has an array of numbers. Now it checks if the given number is less than 40 and not a prime number and returns the square of that number Example: Input {11,23,49,85,25} Output 625 Instructions: You only have to modify conjecture() and assert() functions and context switching is to be done using make context only Use of loops will result in zero marks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 91 3rd Symposium On Mathematical Fundamentals Of Database And Knowledge Base Systems Rostock Germany May 6 9 1991

Authors: Bernhard Thalheim ,Janos Demetrovics ,Hans-Detlef Gerhardt

1991st Edition

3540540091, 978-3540540090

More Books

Students also viewed these Databases questions

Question

What are the major elements of Taylors scientific management?

Answered: 1 week ago

Question

The amount of work I am asked to do is reasonable.

Answered: 1 week ago

Question

The company encourages a balance between work and personal life.

Answered: 1 week ago