/*
* This file is part of flex.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
%{
/* A scanner file to build "scanner.c".
Input language is any text made of spaces, newlines, and alphanumerics.
We create N_THREADS number of threads. Each thread has it's own scanner.
Each thread selects one of the files specified in ARGV, scans it, then
closes it. This is repeated N_SCANS number of times for each thread.
The idea is to press the scanner to break under threads.
If we see "Scanner Jammed", then we know
#ifndef HAVE_PTHREAD_H
int main (int ARGC, char *ARGV[]) {
puts(
"TEST ABORTED because pthread library not available \n"
"-- This is expected on some systems. It is not a flex error.");
/* Exit status for a skipped test */
return 77;
}
#else
#define N_THREADS 4
#define N_SCANS 20
/* Each thread selects the next file to scan in round-robin fashion.
If there are less files than threads, some threads may block. */
/* Allocate and initialize the locks. One for each filename in ARGV. */
file_locks = malloc((size_t) (ARGC-1) * sizeof(pthread_mutex_t));
for( i = 0; i < ARGC-1; i++)
pthread_mutex_init( &file_locks[i], NULL );