<aside> 💡

Tips on defending philosophers on a Xubuntu VM. No spoilers on the subject, just my personal cross-platform experience. Don't hesitate to contribute to this document by contacting me on Slack (@ashishae)!

</aside>

<aside> 🚨 [42 Paris] Salty has authorised to defend Philosopers on a cluster mac using Guacamole (possibly making the defence more predictable). You can find the message below on Slack for reference. Contributed by @oroberts (thanks @rchallie for bringing this up!)

</aside>

1. Look on Slack

Try searching 'philosophers' and reading the first 20 entries. This will help you clarify the subject and find out if something has changed in how the project is evaluated.

2. Think about measuring time precisely.

<aside> 💡 Kudos to @iwillens for pointing this out to me! Step 1 helped me a lot.

</aside>

Consider the following example:

#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>

/*
** Returns the timestamp in milliseconds
*/

long    get_time(void)
{
    struct timeval  tp;
    long            milliseconds;

    gettimeofday(&tp, NULL);
    milliseconds = tp.tv_sec * 1000;
    milliseconds += tp.tv_usec / 1000;
    return (milliseconds);
}

/*
** Prints time, sleeps 200ms, repeats!
*/

int main(void)
{
    long start_time;
		
		// Remember when we started
    start_time = get_time();

    while (1)
    {
				// Print time from start, in ms
        printf("%ld\\n", get_time() - start_time);

				// Sleep 200 times 1000 microseconds (1 millisecond)
        usleep(200 * 1000);
    }
}

This program will print the time, try to sleep for 200 milliseconds, and repeat.